jdadwilson Posted May 9, 2007 Share Posted May 9, 2007 Does anyone know of a function or code that will convert hh:mm PM to hh:mm:ss? I tried the following but it does not work... $date = "2007-05-08" $time = "01:30 PM" $datetime = date("y:m:d h:i:s", strtotime($date . " " . $time) This yelds $datetime = "2007-05-08 01:30:00" which the database interprets as 1:30 AM TIA for any assistance Quote Link to comment https://forums.phpfreaks.com/topic/50591-solved-convert-hhmm-pm-to-hhmmss/ Share on other sites More sharing options...
trq Posted May 9, 2007 Share Posted May 9, 2007 $time = "01:30pm" Quote Link to comment https://forums.phpfreaks.com/topic/50591-solved-convert-hhmm-pm-to-hhmmss/#findComment-248683 Share on other sites More sharing options...
kenrbnsn Posted May 9, 2007 Share Posted May 9, 2007 If you want the time in 24 hour format, you need to use a capital "H" in the format string: <?php $date = "2007-05-08"; $time = "01:30 PM"; $datetime = date("y-m-d H:i:s", strtotime($date . " " . $time); echo $datetime; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/50591-solved-convert-hhmm-pm-to-hhmmss/#findComment-248701 Share on other sites More sharing options...
jdadwilson Posted May 9, 2007 Author Share Posted May 9, 2007 The "H" worked! The book I have has errors in the list indicating that everything is uppercase. Knowing that it is not, I just made the wrong guess as to which was upper and which was lower. Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/50591-solved-convert-hhmm-pm-to-hhmmss/#findComment-248719 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.