mysql 12 小时到 24 小时时间转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/986058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:29:10  来源:igfitidea点击:

mysql 12 hr to 24 hr time conversion

mysql

提问by Vicky

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

我们如何将 AM/PM 中的时间转换为 24 小时格式。例如。(1:30 PM) 应转换为 (13:30)。

回答by tschaible

Dates / Times are stored in mysql the same way regardless of how they are formatted.

日期/时间以相同的方式存储在 mysql 中,无论它们的格式如何。

I believe what you want to do is retrieve the date in a specified format.

我相信您想要做的是以指定格式检索日期。

The DATE_FORMAT() will do this for you.

DATE_FORMAT() 将为您完成此操作。

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

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.

%r 和 %T 分别是 12 小时和 24 小时时间格式。

回答by Rushabh Master

Hi all I think this will help you

大家好,我认为这会帮助你

select STR_TO_DATE('8:25 PM', '%l:%i %p' )

the result will be

结果将是

>20:25:00

回答by Gaurang

1:=> print( date("H:i:s", strtotime("1:30 pm")) );

1:=> 打印(日期("H:i:s", strtotime("1:30 pm")));

output: 13:30:00

输出:13:30:00

回答by user1058982

This may help:

这可能有帮助:

Table: records
Column date: Type date,
Column hours: Type string (am/pm format)


SELECT
date,
hours,
CONCAT(date, ' ', IF(LOCATE('pm',hours) > 0, ADDTIME(TIME(REPLACE(hours, ' pm','')), '12:00:00'),  TIME(REPLACE(hours, ' am',''))))
FROM records