I have to get a date in the future.
I have a date in the past and I need to add "X" days and get the resulting date.
Here is an example of what I want to do
2016-02-28 09:07:22 + 62 days = NewDate
I am using PHP
I have to get a date in the future.
I have a date in the past and I need to add "X" days and get the resulting date.
Here is an example of what I want to do
2016-02-28 09:07:22 + 62 days = NewDate
I am using PHP
You have to use strtotime()
function to convert the date string into seconds, then add the days, and then convert back with date()
function if you want. The code will look like this:
$dateString = '2016-02-28 09:07:22';
$time = strtotime($dateString); //convert to seconds
$timeNew = $time + 62 * 24 * 60 * 60; //add 62 days in seconds
$dateNew = date("Y-m-d H:i:s", $timeNew); //convert back
If you are using the \DateTime()
object, you can do something like:
$past = new \DateTime('2016-02-28 09:07:22');
$interval = new \DateInterval('P64D'); // 64 days
$future = $past->add($interval);