Is there a quicker way of creating a date such as:
echo date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+3, date("Y")));
开发者_运维技巧
Thanks if you can help.
How about strtotime():
date('Y-m-d', strtotime('+3 days'));
You will have to look into strtotime(). I'd imagine your final code would look something like this:
$currentDate = strtotime('today');//your date variable goes here
$futureDate = date('Y-m-d', strtotime('+ 2 days', $currentDate));
echo $futureDate;
Live Demo
If you are using PHP version >= 5.2 I strongly suggest you use the new DateTime object. For example like below:
$futureDate = new DateTime("today");
$futureDate->modify("+2 days");
echo $futureDate->format("Y-m-d");
Live Demo
精彩评论