简体   繁体   English

在PHP中以MySQL Date格式设置的日期中增加天数

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

有没有一种方法可以将一定天数添加到格式为2010-10-17的日期中,而无需像在php中使用strtotime函数那样将其转换为unix时间戳?

You can play around with the DateTime library . 您可以使用DateTime库

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 产出: 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. 因为它们是这里最灵活的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM