How to subtract 4 months from today's date?

霸气de小男生 提交于 2019-11-29 16:22:48

问题


I need to declare two dates in "Ymd" format: $toDate and $fromDate.

$toDate represents today's date and $fromDate needs to be 4 months earlier than today.

$toDate = Date('Ymd');
$fromDate = ?

How do I create $fromDate?


回答1:


Use the magic of strtotime:

$fromDate = date("Ymd", strtotime("-4 months"));



回答2:


see the code below...

$fourmonthsback = date("Ymd", mktime(0, 0, 0, date("m")-4, date("d"),   date("Y")));

OR

$fourmonthsback = mktime(0, 0, 0, date("m")-4, date("d"),   date("Y"));


来源:https://stackoverflow.com/questions/4163387/how-to-subtract-4-months-from-todays-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!