PHP 日期函数 7 天前
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10798228/
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
PHP Date Function Seven days previous
提问by Harsha M V
I am trying to use PHP's Date Function to get the date of 7 days earlier in YYYY-MM-DD format.
我正在尝试使用 PHP 的日期函数以 YYYY-MM-DD 格式获取 7 天前的日期。
date('Y-m-d');
when i try
当我尝试
date('Y-m-d-7');
i get an error
我得到一个错误
回答by Gavin
Use the strtotimemethod provided by PHP.
使用strtotimePHP提供的方法。
date('Y-m-d', strtotime('-7 days'))
date('Y-m-d', strtotime('-7 days'))
Thanks to @lonesomeday for pointing out my mistake in the comments ;)
感谢@lonesomeday 在评论中指出我的错误;)

