PostgreSql: Getting Date in Different Format and group by month

Select  to_char(date_inserted, ‘YYYYMM’) as year_month,

to_char(date_inserted, ‘YYYY’) as year_string,

to_char(date_inserted, ‘month’) as month_string

from myTable

group by year_month

order by year_month;

In the above example,

  • year_month value is displayed as 200804, here 2008 is year and 04 is month.
  • year_string value is displayed as 2008, its a year.
  • month_string value is displayed as april, its the month in date (04 – april month)

One Response to PostgreSql: Getting Date in Different Format and group by month

  1. Pingback: TIP PostgreSql: Getting Date in Different Format and group by month - DbRunas

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.