4

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.

Alex Mcp
  • 19,037
  • 12
  • 60
  • 93
Lee
  • 20,034
  • 23
  • 75
  • 102

2 Answers2

12

How about strtotime():

date('Y-m-d', strtotime('+3 days'));
jasonbar
  • 13,333
  • 4
  • 38
  • 46
0

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

Faisal
  • 4,591
  • 3
  • 40
  • 49