Date minus 1 year?

前端 未结 8 1927
时光取名叫无心
时光取名叫无心 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 14:52

    You can use strtotime:

    $date = strtotime('2010-01-01 -1 year');
    

    The strtotime function returns a unix timestamp, to get a formatted string you can use date:

    echo date('Y-m-d', $date); // echoes '2009-01-01'
    

提交回复
热议问题