In this blog post, you will know how to get the last day of the current month in PHP.
Example-1
1 2 3 4 5 6 7 | <?php $day=new DateTime('last day of this month'); echo $day->format('M jS'); ?> |
Output-
1 | Oct 31st // if this is October 2022 |
Example-2: If any random date, then what is the last day in number?
1 2 3 4 5 6 7 | <?php $dateToTest = "2015-02-01"; echo $lastday = date('t',strtotime($dateToTest)); ?> |
Output- 28