Adding three months to a date in PHP

Adding three months to a date in PHP

Asked on December 25, 2018 in PHP.
Add Comment


  • 3 Answer(s)

    Try this code. It make changes,

    $effectiveDate = date('Y-m-d', strtotime("+3 months", strtotime($effectiveDate)));
    
    
    Answered on December 25, 2018.
    Add Comment

    Use timestamp instead of the formatted date.

    $effectiveDate = strtotime("+3 months", strtotime($effectiveDate)); // returns timestamp
    echo date('Y-m-d',$effectiveDate); // formatted version
    
    Answered on December 25, 2018.
    Add Comment

    Try to use strftime() and date(),It makes much easier.

    $effectiveDate = strtotime("+3 months", strtotime($effectiveDate));
    $effectiveDate = strftime ( '%Y-%m-%d' , $effectiveDate );
    echo $effectiveDate;
    
    Answered on December 25, 2018.
    Add Comment


  • Your Answer

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