PostgreSql: Getting Date in Different Format and group by month
Posted by on April 30, 2009
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)
Pingback: TIP PostgreSql: Getting Date in Different Format and group by month - DbRunas