Mysql Select 声明并即时转换时间戳

Mysql Select statement to and convert timestamp on the fly

我有一个 MYSQL table,它有一个名为 timestamp 的列名称,以字符串格式存储。此列中的时间戳采用以下格式,例如'20/10/2014 05:39 下午'

现在如何 select 一行并将时间戳列即时转换为 24HR 格式。

基本上我想要这样的东西。 SELECT id, user, STR_TO_DATE(timestamp, '%d/%m/%Y %h:%i %p') as timestamp FROM mytable WHERE user="bob";

但这不起作用。看起来它没有识别 STR_TO_DATE sql 函数中的时间戳变量及其对时间戳列的重新调整 NULL。

请帮忙。

我觉得不错:

mysql> SELECT STR_TO_DATE('20/10/2014 05:39 PM', '%d/%m/%Y %h:%i %p');
+---------------------------------------------------------+
| STR_TO_DATE('20/10/2014 05:39 PM', '%d/%m/%Y %h:%i %p') |
+---------------------------------------------------------+
| 2014-10-20 17:39:00                                     |
+---------------------------------------------------------+

(我知道这应该是评论,但为了获得格式,这是一个答案。)

使用 date_format 函数代替 str_to_date: SELECT id, user, date_format(timestamp, '%d/%m/%Y %h:%i %p') as timestamp FROM mytable WHERE user="bob";