oracle 如何在 PostgreSQL 中以日期格式本身添加 AM 或 PM?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19979517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add AM or PM in PostgreSQL in date format itself?
提问by alpha_calling
select to_date(to_char(sysdate,'yyyy-mm-dd hh12:mi:ss AM'), 'yyyy-MM-dd HH12:MI:SS AM') from dual;
从双中选择 to_date(to_char(sysdate,'yyyy-mm-dd hh12:mi:ss AM'), 'yyyy-MM-dd HH12:MI:SS AM');
This works fine in oracle but not in Postgres.
这在 oracle 中工作正常,但在 Postgres 中无效。
回答by fthiella
Instead of sysdate
you should use current_timestamp
, or now()
:
而不是sysdate
你应该使用current_timestamp
, 或now()
:
SELECT TO_CHAR(current_timestamp, 'yyyy-mm-dd hh12:mi:ss AM')
回答by Abhishek Pratap Singh
A table for add AM or PM format itself.
用于添加 AM 或 PM 格式本身的表格。
create table date_tbl ( id serial, Date_time varchar (30) default TO_CHAR(current_timestamp, 'yyyy-mm-dd hh:mi:ss AM') )
创建表 date_tbl ( id serial, Date_time varchar (30) default TO_CHAR(current_timestamp, 'yyyy-mm-dd hh:mi:ss AM') )