Getting last month’s date in php

Getting last month’s date in php

Asked on December 25, 2018 in PHP.
Add Comment


  • 3 Answer(s)

    To get the last month’s date, use the code given below:

    echo date("Y-n-j", strtotime("first day of previous month"));
    echo date("Y-n-j", strtotime("last day of previous month"));
    

    In 3rd november it gives us,

    2014-10-1
    2014-10-31
    
    Answered on December 25, 2018.
    Add Comment

    Use this one line code,

    echo strtotime("-1 month");
    
    

    The output of the above code is the accurate timestamp for last month . Not needed to reset. One can use date() to format the timestampIf if they want this in an English format ,that means,

    echo date("Y-m-d H:i:s",strtotime("-1 month"));
    
    
    Answered on December 25, 2018.
    Add Comment

    Try this answer obviously,

    $prevmonth = date('M Y', strtotime("last month"));
    
    Answered on December 25, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.