Last active
August 29, 2015 14:04
-
-
Save cetver/20f54a59e0a024678428 to your computer and use it in GitHub Desktop.
Postgresql: split month by hours
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with dates as ( | |
select | |
(date_trunc('MONTH', NOW()))::timestamp without time zone --first date of month | |
+ concat( | |
generate_series( | |
0, | |
24 | |
* to_char((date_trunc('MONTH', NOW()) + INTERVAL '1 MONTH - 1 day'), 'DD')::smallint --last day of month | |
-1 | |
), --hours in month | |
' HOUR' | |
)::interval as date | |
) | |
select * | |
from dates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment