Postgresql 错误:小时“16”对于 12 小时制无效

Pra*_*nna 1 postgresql

8/31/2020-16:29:31 PM我的表一栏中有submitted_date。我尝试使用该函数将其转换为时间戳to_timestamp

我输入的命令是:

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

我收到此错误:

ERROR:  hour "16" is invalid for the 12-hour clock
HINT:  Use the 24-hour clock, or give an hour between 1 and 12.
Run Code Online (Sandbox Code Playgroud)

我知道这很愚蠢。但我在这里做错了什么?我试图弄清楚这一点,但我却无能为力。

Ste*_*.sm 12

  • 您的格式字符串错误,应该是 'MM/DD/YYYY-HH24:MI:SS'
  • 8/31/2020-16:29:31 PM 无效的。16:294:29 PM对的?
select to_timestamp('8/31/2020-16:29:31 PM', 'MM/DD/YYYY-HH24:MI:SS "PM"');
Run Code Online (Sandbox Code Playgroud)

工作得很好(格式字符串中带引号的 PM)。