3v4l.org

run code in 300+ PHP versions simultaneously
<?php $schedule = '31/03/2011 01:22 pm'; // %Y, %m and %d correspond to date()'s Y m and d. // %I corresponds to H, %M to i and %p to a $ugly = strptime($schedule, '%d/%m/%Y %I:%M %p'); $ymd = sprintf( // This is a format string that takes six total decimal // arguments, then left-pads them with zeros to either // 4 or 2 characters, as needed '%04d-%02d-%02d %02d:%02d:%02d', $ugly['tm_year'] + 1900, // This will be "111", so we need to add 1900. $ugly['tm_mon'] + 1, // This will be the month minus one, so we add one. $ugly['tm_mday'], $ugly['tm_hour'], $ugly['tm_min'], $ugly['tm_sec'] ); echo $ymd; $new_schedule = new DateTime($ymd); echo $new_schedule->format('Y-m-d H:i:s'); ?>
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Deprecated: Function strptime() is deprecated in /in/GOIBK on line 5 2011-03-31 13:22:002011-03-31 13:22:00
Output for 5.3.7 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
2011-03-31 13:22:002011-03-31 13:22:00

preferences:
191.32 ms | 403 KiB | 292 Q