Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date_trunc by month? Postgresql

Tags:

date

sql

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.

like image 263
Padagomez Avatar asked May 09 '14 15:05

Padagomez


1 Answers

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

like image 182
arserbin3 Avatar answered Sep 30 '22 14:09

arserbin3