上个月的第一天日期功能不起作用?

I have the below code,

$lastmonthLastDay =   date('Y-m-d', strtotime("last day of last month"));
$lastmonthFirstDay= date('Y-m-d', strtotime("first day of -1 month"));

Which works exactly in localhost. But when i push this in live always return 1970-01-01.

Is there anything i missed in server settings ? kindly advice

You can try this:

$firstDay = date('d-m-Y', mktime(0, 0, 0, date("m", strtotime("-1 month")), 1, date("Y",strtotime("-1 month"))));
$lastDay = date('d-m-Y', mktime(-1, 0, 0, date("m"), 1, date("Y")));

It's a more universal way to do it.

I know this is a bit old but... The standard DateTime class in PHP 5.x works nicely for this:

    $last_month = new DateTime('now');
    $last_month->modify('-1 month');
    echo "Last month: ".$last_month->format('Y-m-1 00:00:00')."
";

The format is the same as those for the date() function.