-- Function: day_of_month(date, integer, integer)
-- DROP FUNCTION day_of_month(date, integer, integer);
-- last Sunday of July
-- select day_of_month( to_date('1 Jul 2012', 'DD Mon YYYY'), 0, -1)
-- first Monday of July
-- select day_of_month( to_date('1 Jul 2012', 'DD Mon YYYY'), 1, 1)
-- first Monday of February next year
-- select day_of_month( concat('02-01-',extract (year from current_date) +1)::date, 1, 1)