How can we convert the time in AM/PM to 24-hrs format. For eg. (1:30 PM) should be converted to (13:30).
+1
A:
You could use MySQL's DATE_FORMAT http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format
Sander
2009-06-12 10:50:42
+4
A:
Dates / Times are stored in mysql the same way regardless of how they are formatted.
I believe what you want to do is retrieve the date in a specified format.
The DATE_FORMAT() will do this for you.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format
%r and %T are 12 hour and 24 hour time formats respectively.
tschaible
2009-06-12 10:51:59
I tried giving: select time_format('01:56:39 PM','%T') But it's returning same 01:56:39 PM and giving a warring as "Truncated incorrect time value: '01:56:39 PM' "
Vicky
2009-06-13 06:28:28
The value you are passing in to time_format is still a string, and mysql expects to do it's work on a date value. Try converting to a date first, likeselect time_format(str_to_date('01:56:39 PM','%r'),'%T');
tschaible
2009-06-13 12:38:51
Ok dude I tried and it worked. Thanks a lot
Vicky
2009-06-15 06:42:01