Reputation: 1252
How would I get the date_trunc by month? Would it be like this?
SELECT date_trunc('month', l_date) month
FROM this_table
GROUP BY month
l_date is the column where I would pull the date from.
Upvotes: 9
Views: 33090
Reputation: 6148
Yes, that should work just fine in Postgres
.
Have you tested it?
If your date is 2014-03-16 10:00:00am
:
date_trunc('month', l_date)
would give you 2014-03-01 00:00:00
(sets it to first day of truncated month)
date_part('month', l_date)
would give you 03
which it looks like that is what you are looking for
Upvotes: 11