我想将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
答案 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)