1

How can I convert date format into bigint format in postgresql? for eg: '2018-08-20' to '20180820'

1
postgres=# create table dttest ( dt date ) ;
CREATE TABLE
postgres=# insert into dttest values ( '2018-08-20' ) ;
INSERT 0 1
postgres=# select * from dttest;
     dt     
------------
 2018-08-20
(1 row)

postgres=# select to_char( dt, 'YYYYMMDD' ) from dttest ; 
 to_char  
----------
 20180820
(1 row)

postgres=# 

TO_CHAR and other date/time formatting is documented here.

Oh, and if you actually do want to cast to bigint:

select to_char( dt, 'YYYYMMDD' )::bigint from dttest ; 
|improve this answer|||||
  • Thank sir and i got the new option too from your answer= select to_char( now(), 'YYYYMMDD' )::bigint – Jeevan Gharti Aug 20 '18 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.