Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql 12 hr to 24 hr time conversion

Tags:

mysql

How can we convert the time in AM/PM to 24-hrs format. For eg. (1:30 PM) should be converted to (13:30).

like image 609
Vicky Avatar asked Jun 12 '09 10:06

Vicky


People also ask

How do I convert 12 hour format to 24 hour format in MySQL?

The DATE_FORMAT() will do this for you. %r and %T are 12 hour and 24 hour time formats respectively.

How do you convert 12 hour time to 24 hour time in SQL?

In SQL Server 2012, we can use Format function to have suitable date time format. Use capital letter 'HH:mm:ss' for 24 hour date time format.

How do I add AM PM in MySQL?

But if you want to store AM/PM you need to use varchar datatype. I suggest you to use ->format(); while you get the timestamp data. This will convert the date time format as your wish. For now, as you want to display AM/PM after time, use it like: ->format('g:i A'); This will show time like 10:28 PM .

What is time format in MySQL?

MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.


1 Answers

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.

like image 200
tschaible Avatar answered Sep 26 '22 20:09

tschaible