Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add AM or PM in PostgreSQL in date format itself?

select to_date(to_char(sysdate,'yyyy-mm-dd hh12:mi:ss AM'), 'yyyy-MM-dd HH12:MI:SS AM') from dual;

This works fine in oracle but not in Postgres.

like image 862
alpha_calling Avatar asked Dec 04 '22 08:12

alpha_calling


2 Answers

Instead of sysdate you should use current_timestamp, or now():

SELECT TO_CHAR(current_timestamp, 'yyyy-mm-dd hh12:mi:ss AM')
like image 137
fthiella Avatar answered Dec 26 '22 01:12

fthiella


A table for add AM or PM format itself.

create table date_tbl ( id serial, Date_time varchar (30) default TO_CHAR(current_timestamp, 'yyyy-mm-dd hh:mi:ss AM') )

like image 38
Abhishek Pratap Singh Avatar answered Dec 26 '22 03:12

Abhishek Pratap Singh