如何在PHP中获取上个月的第一个日期和最后日期?

I want to get previous month first date and last date.

$first_date = strtotime('first day of previous month', time());
$previous_month_first_date=date('Y-m-d', $first_date);
$previous_month_last_date=date('Y-m-d', strtotime('last day of previous month'));

Get last day of any other month Enter any month/day/year to get the last day of that month

$lastday = date('t',strtotime('3/1/2009'));

=> Try this code I hope it's useful ..

echo date('Y-m-d', strtotime('first day of last month'));

echo "<br/>";

echo date('Y-m-d', strtotime('last day of last month'));

Output:- https://eval.in/925253

It should be:

date('Y-m-d', strtotime('last day of previous month'));
date('Y-m-d', strtotime('first day of previous month'));

This seems to do it

$first_date = date('Y-m-d', strtotime('first day of previous month'));
$last_date  = date('Y-m-d', strtotime('last day of previous month'));
    echo $first_date;
    echo '<br>';
    echo $last_date;

You are already getting the first date of previous month by:

$first_date = strtotime('first day of previous month', time());

Just add ('Y-m-t') in date format to get last date of previous month:

$previous_month_first_date=date('Y-m-d', $first_date);
$previous_month_last_date=date('Y-m-t', $first_date);