[英]How can I find the date that is 1 day later than another date in PHP?
How can I find the next day's date after a given date. 如何找到给定日期之后的第二天的日期。
For example, I have a date 2011-11-31
. 例如,我有一个日期
2011-11-31
。 How can I get the next date ( 2011-12-01
) using PHP? 如何使用PHP获取下一个日期(
2011-12-01
)?
Similarly, how would I get the previous day's date? 同样,我将如何获得前一天的日期?
$nextdate = date("Y-m-d",strtotime($olddate." +1 day"));
You can use the strtotime() function in php: 您可以在php中使用strtotime()函数:
$date="2011-11-11"; $日期= “2011-11-11”;
$nextdate = date('Ym-d', strtotime($date . " +1 day")); $ nextdate = date('Ym-d',strtotime($ date。“ +1天”));
echo $nextdate; echo $ nextdate;
It will echo as "2011-11-12". 它将回显为“ 2011-11-12”。
Similarly to find the previous date use: 同样,要查找上一个日期,请使用:
$nextdate = date('Ym-d', strtotime($date . " -1 day")); $ nextdate = date('Ym-d',strtotime($ date。“ -1 day”));
It will echo as "2011-11-10". 它将回显为“ 2011-11-10”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.