Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL TO_CHAR() Remove Padding on Month Field

Hopefully and easy adjustment. I've googled and not found anything on this. I'm using the DBvis Client to run queries against a Postgres database table.

I've used the to_char() function quite a bit with Oracle and PostgreSQL queries, but guess I've never noticed this behavior.

SELECT TO_CHAR(created_at, 'Month DD, YYYY') AS DATE_CREATED...;

In the result set, the month field is being padded with spaces out to 9 spaces, then the day and year:

February  26, 2018
January   01, 2000
July      23, 2014
September 01, 2015
December  15, 2015
May       31, 2016

I know now, from the docs, that this is the way the month format works, but is there a way to get the full month without the extra padding? I'd like it to look like so:

February 26, 2018
January 01, 2000
July 23, 2014
September 01, 2015
December 15, 2015
May 31, 2016

Each date will be followed by the content of a text field and I think they would just read easier if there were only one space between the Month and Day.

May 31, 2016 This is my text notes for this record The date portion of this record is not aesthetically pleasing or easy on the eyes.

Thanks for any tips.

like image 418
John Cowan Avatar asked Aug 12 '19 11:08

John Cowan


1 Answers

Use the "fill mode" FM which - in contrast do its name - does not fill the value with spaces:

TO_CHAR(created_at, 'FMMonth DD, YYYY')
like image 159
a_horse_with_no_name Avatar answered Nov 17 '22 09:11

a_horse_with_no_name