Skip to main content
deleted 1 character in body; edited tags; edited title
Source Link
Paul White
  • 95.7k
  • 30
  • 440
  • 691

PostgreSQL Removing Leading Zerosleading zeros from month and day

Someone in a PostgreSQL chat room gave me this syntax. It is used in a VIEW that outputs an RSS feed link:

to_char(tips_chronic_pain_weekly_selection.start_date, 'YYYY/MM/DD'::text) Example output: 2021/09/13 

I am not familiar with how this works. Am I able to remove the trailingleading 0 in both month and day? This was given to me several months ago as a shorten version of:

concat( extract( YEAR FROM tips_physical_disability_weekly_selection.start_date), '/', extract( MONTH FROM tips_physical_disability_weekly_selection.start_date), '/', extract( DAY FROM tips_physical_disability_weekly_selection.start_date) ) 

PostgreSQL Removing Leading Zeros

Someone in a PostgreSQL chat room gave me this syntax. It is used in a VIEW that outputs an RSS feed link:

to_char(tips_chronic_pain_weekly_selection.start_date, 'YYYY/MM/DD'::text) Example output: 2021/09/13 

I am not familiar with how this works. Am I able to remove the trailing 0 in both month and day? This was given to me several months ago as a shorten version of:

concat( extract( YEAR FROM tips_physical_disability_weekly_selection.start_date), '/', extract( MONTH FROM tips_physical_disability_weekly_selection.start_date), '/', extract( DAY FROM tips_physical_disability_weekly_selection.start_date) ) 

Removing leading zeros from month and day

Someone in a PostgreSQL chat room gave me this syntax. It is used in a VIEW that outputs an RSS feed link:

to_char(tips_chronic_pain_weekly_selection.start_date, 'YYYY/MM/DD'::text) Example output: 2021/09/13 

I am not familiar with how this works. Am I able to remove the leading 0 in both month and day? This was given to me several months ago as a shorten version of:

concat( extract( YEAR FROM tips_physical_disability_weekly_selection.start_date), '/', extract( MONTH FROM tips_physical_disability_weekly_selection.start_date), '/', extract( DAY FROM tips_physical_disability_weekly_selection.start_date) ) 
Source Link

PostgreSQL Removing Leading Zeros

Someone in a PostgreSQL chat room gave me this syntax. It is used in a VIEW that outputs an RSS feed link:

to_char(tips_chronic_pain_weekly_selection.start_date, 'YYYY/MM/DD'::text) Example output: 2021/09/13 

I am not familiar with how this works. Am I able to remove the trailing 0 in both month and day? This was given to me several months ago as a shorten version of:

concat( extract( YEAR FROM tips_physical_disability_weekly_selection.start_date), '/', extract( MONTH FROM tips_physical_disability_weekly_selection.start_date), '/', extract( DAY FROM tips_physical_disability_weekly_selection.start_date) )