Re: function to find last day of month

From: <btober(at)seaworthysys(dot)com>
To: <jlee(at)scri(dot)sari(dot)ac(dot)uk>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: function to find last day of month
Date: 2003-12-05 13:32:13
Message-ID: 64763.216.238.112.88.1070631133.squirrel@$HOSTNAME
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Roderick A. Anderson 2003-12-05 13:43:49 Re: Groups vs. Roles
Previous Message Michael Meskes 2003-12-05 13:08:11 Re: ecpg -e