smerny Posted November 15, 2009 Share Posted November 15, 2009 I'd like to have a user enter two times (within a single day) and be able to tell the difference between them... I was trying to figure out a way and wanted to check what decimal value a time format string would give, so i did this: $time = "8:30" * 1.0 and got "8"? (I was hoping for 8.5) Anyway, what is the best way to do this? - I have an input for start and end times. - I can assume that if a start time is 8 to 11:59, it is AM - I can assume that if an end time is 12 to 10, it is PM Quote Link to comment https://forums.phpfreaks.com/topic/181577-solved-difference-between-user-inputted-times/ Share on other sites More sharing options...
smerny Posted November 15, 2009 Author Share Posted November 15, 2009 I was thinking if I could get them in decimal values, like say 8:30 is start and 6:00 is end... if I could get them to be 8.5 and 6, I could then do something like: if (1 <= $start && $start < $start += 12; if (1 <= $end && $end < 10) $end += 12; $difference = floor($end - $start) .":". round((($end-$start) - floor($end - $start)) * 60); Quote Link to comment https://forums.phpfreaks.com/topic/181577-solved-difference-between-user-inputted-times/#findComment-957739 Share on other sites More sharing options...
smerny Posted November 15, 2009 Author Share Posted November 15, 2009 nevermind, I came up with my own little thing... $in = explode(":",$_POST['in'][$i]); $in = $in[0] + $in[1] /60; but if anyone thinks i should be doing this a different way, i'm open Quote Link to comment https://forums.phpfreaks.com/topic/181577-solved-difference-between-user-inputted-times/#findComment-957750 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.