Peter Senyszyn Peter Senyszyn - 2 months ago 8
SQL Question

Changing ISO 8601 date string to 24 hours from its current value

I have an ISO 8601 string like so:

2016-09-26T20:38:15.793Z


Now, I want to push the date forward 24 hours, but in the "Y-m-d H:i:s" format. I experimented with the following:

//$date1 is ISO 8601 string
date("Y-m-d H:i:s", strtotime($date1, '+24 hours'));


But unfortunately that's not working. Am I on the right track or completely wrong?

Thanks

Answer

Use the DateTime class. Make a new instance, add 24 hours to it and format it.

$dt = new DateTime('2016-09-26T20:38:15.793Z');
$dt->modify('+24 hours'); 
echo $dt->format('Y-m-d H:i:s');

https://3v4l.org/CHmmm

Comments