temujinleal Posted December 29, 2007 Share Posted December 29, 2007 Good day experts!! I would like to ask if is it possible in a date() function to determine that it will only change to PM or AM if it is already 1 o clock? for example: if the time now is 12AM, the next hour will be 1PM then after 12hours, it will be 1AM but before 1AM, it is still 12PM... I'm just concern about the transition from AM to PM... Thanks!! cheers!! Quote Link to comment https://forums.phpfreaks.com/topic/83584-solved-question-about-date-time/ Share on other sites More sharing options...
PHP_PhREEEk Posted December 29, 2007 Share Posted December 29, 2007 date() requires a timestamp of some form... whether given directly or created with mktime(). No timestamp supplied implies the current time timestamp. The timestamp always knows whether AM or PM in 12 hour formatted displays, so if you include the AM/PM indicator, it will always be accurate. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83584-solved-question-about-date-time/#findComment-425243 Share on other sites More sharing options...
temujinleal Posted December 29, 2007 Author Share Posted December 29, 2007 sir is it possible that i can modify the transition of AM to PM if the time is 1 o clock instead of 12 o clock? Quote Link to comment https://forums.phpfreaks.com/topic/83584-solved-question-about-date-time/#findComment-425246 Share on other sites More sharing options...
PHP_PhREEEk Posted December 29, 2007 Share Posted December 29, 2007 If the time is 1 AM and you want it PM, just add or subtract 12 hours from it... I think that you are not being clear with exactly what you want to do here. Please give us an actual example of what you're doing... PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83584-solved-question-about-date-time/#findComment-425247 Share on other sites More sharing options...
Barand Posted December 29, 2007 Share Posted December 29, 2007 the switch from AM to PM or PM to AM is made instantly, not after an hour has elapsed If you run this script, which increments the time by 1 second <?php echo "<h3>At Midday</h3>"; $start = mktime (11,59,55); for ($i=0; $i<10; $i++) echo date ('g:i:s A', strtotime("+$i seconds", $start)), '<br>'; echo "<h3>At Midnight</h3>"; $start = mktime (23,59,55); for ($i=0; $i<10; $i++) echo date ('g:i:s A', strtotime("+$i seconds", $start)), '<br>'; ?> you get [pre]At Midday 11:59:55 AM 11:59:56 AM 11:59:57 AM 11:59:58 AM 11:59:59 AM 12:00:00 PM 12:00:01 PM 12:00:02 PM 12:00:03 PM 12:00:04 PM At Midnight 11:59:55 PM 11:59:56 PM 11:59:57 PM 11:59:58 PM 11:59:59 PM 12:00:00 AM 12:00:01 AM 12:00:02 AM 12:00:03 AM 12:00:04 AM Quote Link to comment https://forums.phpfreaks.com/topic/83584-solved-question-about-date-time/#findComment-425248 Share on other sites More sharing options...
temujinleal Posted December 29, 2007 Author Share Posted December 29, 2007 sir what i'm trying to say is this example... 11:00 AM 11:30 AM 12:00 AM 12:30 AM 1:00 PM 1:30 PM and so on then 11:00 PM 11:30 PM 12:00 PM 12:30 PM 1:00 AM 1:30 AM Thanks for your replies!! i really appreciate it... :) Quote Link to comment https://forums.phpfreaks.com/topic/83584-solved-question-about-date-time/#findComment-425250 Share on other sites More sharing options...
Barand Posted December 29, 2007 Share Posted December 29, 2007 I don't why you want when it's clearly a wrong representation of the time, but you could fool it by subtracting an hour when outputting the am/pm bit <?php $time = strtotime('2007-12-29 12:30:00'); echo 'The time is ' . date ('g:i', $time) . date('A', strtotime('-1 hours', $time)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83584-solved-question-about-date-time/#findComment-425255 Share on other sites More sharing options...
temujinleal Posted December 29, 2007 Author Share Posted December 29, 2007 i think it is really not possible to change the transition of AM PM... thanks for your replies!!! cheers!! Quote Link to comment https://forums.phpfreaks.com/topic/83584-solved-question-about-date-time/#findComment-425257 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.