Created
June 21, 2018 16:45
-
-
Save robozavri/48286805fcf83ab51fe666894650a7cc to your computer and use it in GitHub Desktop.
php add datetime to datetime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$datas = explode("/",'23/04/2018'); | |
$correctDAta = $datas[2].'-'.$datas[1].'-'.$datas[0].' 10:00:00'; | |
echo $correctDAta; | |
echo '<hr>'; | |
$time = explode(":",'02:50:50'); | |
//var_dump($time); | |
//exit(); | |
//echo $time[0]; | |
$updatedate = 'PT'. $time[0] .'H'. $time[1] .'M'. $time[2].'S'; | |
$date = new DateTime($correctDAta); | |
$date->add(new DateInterval($updatedate)); | |
echo $date->format('Y-m-d H:i:s') . "\n"; | |
$date = new DateTime('2000-01-01'); | |
$date->add(new DateInterval('PT10H30S')); | |
echo $date->format('Y-m-d H:i:s') . "\n"; | |
$date = new DateTime('2000-01-01'); | |
$date->add(new DateInterval('P7Y5M4DT4H3M2S')); | |
echo $date->format('Y-m-d H:i:s') . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment