-5

I tried the top answer of this question adding 1 day to a DATETIME format value but it didnt work. Im trying to get an easy solution for this: eg: 2017-12-31 +5 day. And I'd like to make a function where i give the current date and the days, or months etc, or if theres a built-in php that can do this, thats eaven better.

STATESZ
  • 1
  • 3
  • 1
    _"it didnt work"_, but what did it actually do? – Don't Panic Aug 15 '17 at 18:06
  • 1
    Please edit your question to show _how_ you tried it, what input you gave it, what output you expected, and what output you got instead. Without that information, "I tried it but it didn't work" is not useful information. – Don't Panic Aug 15 '17 at 18:09

2 Answers2

0
$date = "2017-12-31";

echo date("Y-m-d", strtotime($date . " +5 days"));

Strtotime() can translate some sentences to actions. See example 1

Wimanicesir
  • 4,606
  • 2
  • 11
  • 30
Andreas
  • 23,610
  • 6
  • 30
  • 62
0

here is a alternative function:

function get5daysLater($date, $extra_days = 5)
{
    echo date('Y-m-d', strtotime($date) +$extra_days *24*60*60);
}

Example of use:

echo get5daysLater("2017-12-07");
Amit Joshi
  • 1,334
  • 1
  • 8
  • 10
  • Allthough it will work most of the times, if it's daylight saving you could go short on one hour with this. – Andreas Aug 15 '17 at 18:08