如何转换' 10-OCT-17 07.57.1​​4.253290000 AM'文字转换为日期格式' 2017-10-10 07:57:14'?

时间:2017-11-28 11:28:49

标签: sql postgresql datetime

我想将10-OCT-17 07.57.14.253290000 AM日期格式转换为2017-10-10 07:57:14

10-OCT-17 12.57.14.253290000 PM日期格式为2017-10-10 12:57:14

10-OCT-17 07.57.14.253290000 PM日期格式为2017-10-10 19:57:14

我想要考虑 AM PM

cast(to_timestamp(pub_ts ,'dd-mon-yy HH.MI.SS') as timestamp without time zone)

pub_ts是一个文本。我用这15天就可以了。

转换

10-OCT-17 12.57.14.253290000 PM日期格式为2017-10-10 00:57:14

1 个答案:

答案 0 :(得分:1)

我假设你只是need a right mask? EG:

postgres=# with e(v) as (values('10-OCT-17 12.57.14.253290000 PM'),('10-OCT-17 12.57.14.253290000 AM'))
select v,to_timestamp(v,'DD-MON-YY HH12.MI.SS.US000 AM')::timestamp(0) from e;
                v                |    to_timestamp
---------------------------------+---------------------
 10-OCT-17 12.57.14.253290000 PM | 2017-10-10 12:57:14
 10-OCT-17 12.57.14.253290000 AM | 2017-10-10 00:57:14
(2 rows)