Re: function to find last day of month - Mailing list pgsql-general

From
Subject Re: function to find last day of month
Date
Msg-id 64763.216.238.112.88.1070631133.squirrel@$HOSTNAME
Whole thread Raw
In response to function to find last day of month  ("Jennifer Lee" <jlee@scri.sari.ac.uk>)
List pgsql-general
> Hello,
>
> Does anyone happen to have a function, prefereably in pl/pgsql, which
> given the month and year will return the last day in that month?
>

Something like this might get you started:

CREATE OR REPLACE FUNCTION public.fom(date)
  RETURNS date AS
'
SELECT COALESCE($1, CURRENT_DATE)-EXTRACT(DAY FROM COALESCE($1,
CURRENT_DATE))::INTEGER+1;
'
  LANGUAGE 'sql' VOLATILE;



CREATE OR REPLACE FUNCTION public.lom(date)
  RETURNS date AS
'
SELECT fom(date (COALESCE($1, CURRENT_DATE) + interval \'1 month\'))-1;
'
  LANGUAGE 'sql' VOLATILE;


~Berend Tober




pgsql-general by date:

Previous
From: Michael Meskes
Date:
Subject: Re: ecpg -e
Next
From: "Roderick A. Anderson"
Date:
Subject: Re: Groups vs. Roles