문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top