postgreSQL SELECT the last day of month
You can select the last day of month.
SELECT (date_trunc('MONTH', ('201608'||'01')::date) + INTERVAL '1 MONTH - 1 day')::DATE;
201608 is replaceable with a variable.
Count the number of records per week
SELECT date_trunc('week', <>) AS "Week" , count(*) FROM <> GROUP BY 1 ORDER BY 1;