SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- https://pgexercises.com/questions/date/daysremaining.html |
| 1 | + | -- https://pgexercises.com/questions/date/daysinmonth.html |
| 2 | - | -- solved for today, not for their date |
| 2 | + | -- date_part does not work for the second column of the second clause, but date_trunc does |
| 3 | ||
| 4 | - | select |
| 4 | + | with gs as (select generate_series( |
| 5 | - | (date_trunc('month', CURRENT_TIMESTAMP) + '1 month'::INTERVAL) - date_trunc('day', CURRENT_TIMESTAMP) as remaining |
| 5 | + | '2012-01-01'::timestamp, |
| 6 | '2012-12-31'::timestamp, | |
| 7 | '1 month'::interval) as month) | |
| 8 | ||
| 9 | select date_part('month', month) as m,
| |
| 10 | (date_trunc('month', month)+'1 month'::INTERVAL)-date_trunc('month', month) as len
| |
| 11 | from gs |