NonplayerCharacter

PGexercises.com | Count days in each month

Mar 22nd, 2022
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- https://pgexercises.com/questions/date/daysinmonth.html
  2. -- date_part does not work for the second column of the second clause, but date_trunc does
  3.  
  4. with gs as (select generate_series(
  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
Advertisement
Add Comment
Please, Sign In to add comment