获取上个月的日期范围

thr*_*ee3 4 php datetime date strtotime mktime

我需要帮助以下列格式获取前几个月的完整日期范围:Ymd

我已经成功地获得了"这个"月份的完整日期范围,但没有达到"前一个"月份的完整日期范围.

任何帮助是极大的赞赏!

Tad*_*eck 10

这可以正确完成工作:

echo date('Y-m-01 - Y-m-t', strtotime('previous month'));
Run Code Online (Sandbox Code Playgroud)

以下是证明:http://ideone.com/L82ZW


Raj*_*hal 8

    $last_month_first_day=strtotime('first day of last month');
    $no_of_days=date('t',$last_month_first_day);
    $date_value=$last_month_first_day;
    for($i=0;$i<$no_of_days;$i++)
    {
        echo date('Y-m-d',$date_value)."<br>";
        $date_value=strtotime("+1 day",$date_value);
    }
Run Code Online (Sandbox Code Playgroud)

此代码将打印您想要的内容..

第一次约会:

echo date('Y-m-d',strtotime('first day of last month'));
Run Code Online (Sandbox Code Playgroud)

上次日期:

echo date('Y-m-d',strtotime('last day of last month'));
Run Code Online (Sandbox Code Playgroud)