首页 > 解决方案 > Postgresql 错误:小时“16”对于 12 小时制无效

问题描述

8/31/2020-16:29:31 PMsubmitted_date我的桌子的列。我尝试使用该to_timestamp函数将其转换为时间戳。

我输入的命令是:

select TO_TIMESTAMP(submitted_date, 'MM/DD/YYYY-HH24:MI:SS PM') from table;

我得到这个错误:

ERROR:  hour "16" is invalid for the 12-hour clock
HINT:  Use the 24-hour clock, or give an hour between 1 and 12.

我知道这很愚蠢。但是我在这里做错了什么?我没有智慧试图解决这个问题。

标签: postgresql

解决方案


  • Your format string is wrong, should be 'MM/DD/YYYY-HH24:MI:SS'
  • 8/31/2020-16:29:31 PM is invalid. 16:29 is 4:29 PM, right?
select to_timestamp('8/31/2020-16:29:31 PM', 'MM/DD/YYYY-HH24:MI:SS "PM"');

works just fine (with quoted PM in the format string).


推荐阅读