neilfurry Posted July 31, 2015 Share Posted July 31, 2015 Hi there, i've been struggling on a problem converting datetime format to ISO8601 here is my code: $string = $_REQUEST['sched-date']." ".$_REQUEST['sched-start']; $start_string = date("Y-m-d H:i", strtotime($string)); $newformat = date('c',$start_string); echo "String: ".$string; echo "\n"; echo "ISO Format: ".$newformat; AND Here is the output: String: 07/30/2015 07:45 AM ISO Format: 1969-12-31T17:33:35-07:00 You will notice that the ISO output is not correct. can you help me with this? Thanks in advance. Neil Link to comment https://forums.phpfreaks.com/topic/297566-need-help-on-time-formating/ Share on other sites More sharing options...
requinix Posted July 31, 2015 Share Posted July 31, 2015 The second argument to date() is a number, not a string. See how the first time you used it the value came from strtotime() but the second time it came from date()? $time = strtotime($_REQUEST['sched-date']." ".$_REQUEST['sched-start']); $newformat = date('c', $time); Link to comment https://forums.phpfreaks.com/topic/297566-need-help-on-time-formating/#findComment-1517801 Share on other sites More sharing options...
gizmola Posted July 31, 2015 Share Posted July 31, 2015 How about: $string = $_REQUEST['sched-date']." ".$_REQUEST['sched-start']; $date = DateTime::createFromFormat('Y-m-d H:i', $string); echo "String: $string\n"; echo "ISO Format: " . $date->format('c'); Link to comment https://forums.phpfreaks.com/topic/297566-need-help-on-time-formating/#findComment-1517833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.