用PHP添加日期 [英] Adding Days to a Date with PHP

查看:106
本文介绍了用PHP添加日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在PHP中添加一定的日期。但是,我使用的所有代码都不工作。以下是我目前遇到的问题:

I am trying to add a certain amount of days to a set date in PHP. However, all of the code I use is not working. Here is the code I am currently experiencing problems with:

echo date("2013-12-01", strtotime("+7 days"));

我想在上面的日期添加7天。当我回覆这个代码时,它打印2013-12-01。有没有办法这样做?

I wanting to add 7 days to the date above. When I echo out this code, it just prints '2013-12-01'. Is there a way to do this?

谢谢

推荐答案

为了完整起见,以下是 DateTime( )

For the sake of completeness, here's how you do it with DateTime():

$datetime = new DateTime("2013-12-01");
$datetime->add(new DateInterval('P7D'));
echo $datetime->format('Y-m-d');

$datetime = new DateTime("2013-12-01");
$datetime->modify('+7 days');
echo $datetime->format('Y-m-d');

这篇关于用PHP添加日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆