tags:

views:

253

answers:

2

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
+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
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
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
Ok dude I tried and it worked. Thanks a lot
Vicky