Finding the Last Day of the Month in PHP
To obtain the last day of any given month in PHP, we can leverage a combination of the date and strtotime functions. Here's how:
Answer:
The date function, when passed the "t" format specifier, combined with the timestamp generated by strtotime for a given date, provides the number of days in that month.
Example:
To retrieve the last day of November 2009:
$a_date = "2009-11-23"; echo date("Y-m-t", strtotime($a_date));
Output:
2009-11-30
Similarly, for December 2009:
$a_date = "2009-12-23"; echo date("Y-m-t", strtotime($a_date));
Output:
2009-12-31
The above is the detailed content of How Can I Find the Last Day of a Month Using PHP?. For more information, please follow other related articles on the PHP Chinese website!