Mateusz Urbański
Mateusz Urbański

Reputation: 7872

Convert timestamp in PostgreSQL

I want to convert timestamp column to the following format in PostgreSQL:

2/28/2018

I've tried:

to_char((sr.created_at), 'MM/DD/YYYY')

but that gives me:

02/28/2018

Is there way to do that in PostgreSQL?

Upvotes: 2

Views: 180

Answers (1)

Kaushik Nayak
Kaushik Nayak

Reputation: 31716

You may use the FM prefix to suppress leading zeroes.

knayak=# select TO_CHAR(DATE '2019-01-01','FMMM/FMDD/YYYY');
 to_char
----------
 1/1/2019
(1 row)

Upvotes: 5

Related Questions