Home > Backend Development > PHP Tutorial > How Can I Find the Last Day of a Month Using PHP?

How Can I Find the Last Day of a Month Using PHP?

Patricia Arquette
Release: 2024-12-29 07:42:10
Original
163 people have browsed it

How Can I Find the Last Day of a Month Using PHP?

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));
Copy after login

Output:

2009-11-30
Copy after login

Similarly, for December 2009:

$a_date = "2009-12-23";
echo date("Y-m-t", strtotime($a_date));
Copy after login

Output:

2009-12-31
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template