2

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?

4
  • 1
    You want to remove 0? Commented Dec 7, 2018 at 7:45
  • Yeah, I want to remove 0 from the month. Commented Dec 7, 2018 at 7:47
  • 1
    What do you want for 1st Jan 2019? 1/1/2019 or 1/01/2019 ? Commented Dec 7, 2018 at 7:51
  • I want 1/1/2019 Commented Dec 7, 2018 at 7:54

1 Answer 1

5

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.