Date minus 1 year?

前端 未结 8 1955
时光取名叫无心
时光取名叫无心 2020-11-27 14:28

I\'ve got a date in this format:

2009-01-01

How do I return the same date but 1 year earlier?

8条回答
  •  野性不改
    2020-11-27 15:05

    // set your date here
    $mydate = "2009-01-01";
    
    /* strtotime accepts two parameters.
    The first parameter tells what it should compute.
    The second parameter defines what source date it should use. */
    $lastyear = strtotime("-1 year", strtotime($mydate));
    
    // format and display the computed date
    echo date("Y-m-d", $lastyear);
    

提交回复
热议问题