php 如何从今天的日期减去4个月?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4163387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:09:47 来源:igfitidea点击:
How to subtract 4 months from today's date?
提问by Jason94
I need to declare two dates in "Ymd"
format: $toDate
and $fromDate
.
我需要以"Ymd"
格式声明两个日期:$toDate
和$fromDate
。
$toDate
represents today's date and $fromDate
needs to be 4 months earlier than today.
$toDate
代表今天的日期,$fromDate
需要比今天早 4 个月。
$toDate = Date('Ymd');
$fromDate = ?
How do I create $fromDate
?
我如何创建$fromDate
?
回答by Prabhu M
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"));