简体   繁体   English

将任何输入时间戳 ex (4/25/2021 20.01.42) 转换为正确的 Postgres 时间戳 (YYYY-MM-DD HH12:MI:SS)

[英]Convert any input timestamp ex (4/25/2021 20.01.42) to Correct Postgres TimeStamp (YYYY-MM-DD HH12:MI:SS)

I always get random timestamp format input for a data/time field from a file.我总是从文件中获取数据/时间字段的随机时间戳格式输入。 Irrespective of the input, i always want it get converted into correct Postgres timestamp format.无论输入如何,我总是希望它被转换为正确的 Postgres 时间戳格式。

ex1: (4/25/2021 20.01.42) to Correct Postgres TimeStamp (YYYY-MM-DD HH12:MI:SS) ex1: (4/25/2021 20.01.42) 更正 Postgres 时间戳 (YYYY-MM-DD HH12:MI:SS)

ex2: sometime the format we receive from file is (10/05/2022 09:17:23) ex2:有时我们从文件中收到的格式是 (10/05/2022 09:17:23)

I'm getting error as我收到错误

invalid date format or convert 24 hr clock to 12 hr for example-1 etc.无效的日期格式或将 24 小时时钟转换为 12 小时例如 example-1 等。

Can we write a generic conversion statement in Postgres?我们可以在 Postgres 中编写通用转换语句吗?

24h: 24小时:

  select to_timestamp('4/25/2021 20.01.42','MM/DD/YYYY HH24:MI:SS');

12h: 12小时:

select to_char( to_timestamp ('4/25/2021 20.01.42','MM/DD/YYYY HH24:MI:SS') , 'HH12:MI:SS PM' )

Further info: https://www.postgresql.org/docs/current/datetime-appendix.html更多信息: https://www.postgresql.org/docs/current/datetime-appendix.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Postgres 中将 YYYY-MM-DDTHH:mm:ss.SSSZ 时间戳转换为 YYYY-MM-DD HH:mm:ss - How to convert YYYY-MM-DDTHH:mm:ss.SSSZ timestamp to YYYY-MM-DD HH:mm:ss in Postgres 如何转换为日期时间YYYY-MM-DD HH:mi:ss - How to Convert to Datetime YYYY-MM-DD HH:mi:ss 将秒转换为 yyyy-mm-dd hh:mm:ss PostgreSQL - Convert seconds to yyyy-mm-dd hh:mm:ss PostgreSQL 如何将 YYYY-MM-DD 字符串格式转换为 Golang 中的时间戳? - How to convert YYYY-MM-DD string format to timestamp in Golang? 使用psql \\ copy导入带有时间戳列(.dd.mm.yyyy hh.mm.ss)的.csv - Importing .csv with timestamp column (dd.mm.yyyy hh.mm.ss) using psql \copy 如何将格式为 'YYYY-DD-MM HH:MI:SS.MS +00:00' 的字符串转换为 postgres timestamptz,其中最后四个字符是时区偏移量? - How do I convert a string of the form 'YYYY-DD-MM HH:MI:SS.MS +00:00' where last four chars are a timezone offset into a postgres timestamptz? Postgres 时间戳到 DATE dd-mm-yyyy - Postgres Timestamp to DATE dd-mm-yyyy 将日期'yyyymmdd hh24:MI:SS'转换为yyyy-mm-ddTHH24:MI:SS - Convert date 'yyyymmdd hh24:MI:SS' to yyyy-mm-ddTHH24:MI:SS 在Postgresql中存储格式为yyyy-mm-dd hh:mm:ss的日期的数据类型 - Datatype to store date of format yyyy-mm-dd hh:mm:ss in postgresql 以oracle和PostgreSQL查询以yyyy-MM-dd'T'HH:mm:ss.SSSZ格式打印日期 - Query to print date in yyyy-MM-dd'T'HH:mm:ss.SSSZ format in oracle and postgresql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM