- Instant help with your Php coding problems

Get the last day of a month from date in PHP

Question:
How to get the last day of a month from date in PHP?
Answer:
$date = new DateTime($dateStr);
$lastDay = $date->format('Y-m-t');
Description:

To get the last day of a month in PHP simply create a DateTime object first. If you have a DateTime object you can get its formatted value. The format string you need in this case is t which represents the number of days in the given month.

Share "How to get the last day of a month from date in PHP?"