How to get last day of the month using php ?
<?php
echo date('?-?-?');
?>
How to get last day of the month using php ?
<?php
echo date('?-?-?');
?>
<?php
$day=new DateTime('last day of this month');
echo $day->format('M jS');
?>
The date function documentation says that t
represents number of days in current month:
$day = date( 't-m-Y' );
try this
$day=date('Y-m-t'); // gives last day of current month
OR
$d = new DateTime( '2013-05-03' );
echo $d->format( 'Y-m-t' );
Try:
$last_day = date('t-m-Y');
where t
means the last date of the current month.
How can I find the first and last date in a month using PHP?
Try this
$date = new DateTime();
$lastDayOfMonth = $date->modify(
sprintf('+%d days', $date->format('t') - $date->format('j'))
);