Page 1 of 1

DATETIME data type. Changing time from 24hr to 12hr.

Posted: Wed Apr 26, 2006 2:10 pm
by mattyboi
Any ideas how I can change the time from 24hr time to 12hr time, and vise versa.

Input on a form element would be in 12hr time, would have to format it to 24hr time to store it in the TIME data type. Output would be in 24hr time would like to display it in 12hr time on the page.

Thanks

Posted: Wed Apr 26, 2006 2:14 pm
by pickle

Code: Select all

$hour += ($afternoon) ? 12 : 0;

Posted: Wed Apr 26, 2006 2:34 pm
by mattyboi
can you explain how this works. still learning.

Posted: Wed Apr 26, 2006 2:39 pm
by pickle
When someone enters a time, is there a checkbox or radio button to set whether or not the time is AM or PM? When the form is submitted, check the value of that variable and add 12 if it's set to PM.

Posted: Wed Apr 26, 2006 2:41 pm
by feyd

Posted: Wed Apr 26, 2006 4:18 pm
by timvw

Code: Select all

SELECT DATE_FORMAT('datecolumn', '%r') AS nicetime
FROM table

For 12am -> datetime i'd have a look at (php) strtotime and mysql FROM_UNIXTIME functions.