开发者

Add number of days to a date formatted in MySQL Date in PHP

开发者 https://www.devze.com 2023-01-20 04:14 出处:网络
Is there a way to add a certain number of days to a date formatted like 2010-10-17 without converting it to a unix timestamp lik开发者_如何学运维e using the function strtotime in php?You can play arou

Is there a way to add a certain number of days to a date formatted like 2010-10-17 without converting it to a unix timestamp lik开发者_如何学运维e using the function strtotime in php?


You can play around with the DateTime library.

So, based on your description, something like the following should do the trick:

$date = new DateTime('2010-10-17');
$date->add(new DateInterval('P10D')); //adding ten days
echo $date->format('Y-m-d') . "\n";

Outputs: 2010-10-27


Although I'm curious as to why you do not want to work with timestamps? As they're the most flexible choice here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号