From: | Rajesh nalankal <rajeshnalankal(at)yahoo(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | last dtae of the month |
Date: | 2004-10-03 06:41:37 |
Message-ID: | 20041003064137.18925.qmail@web61008.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
hi every body
here is my function to get last day of the month. but it causes error while executing.
please help
/*
This function returns the last day of the given date's month.
-- Logic --
extract month and year from the given date
build a date of next month by concatnating these values and any day* ( 1- 28)
then substract the given day* from the concatnated date.
*/
declare
dteGivenDate date;
intGivenMonth integer;
intGivenYear integer;
intNextMonth integer;
dteLastDay date;
strTmp varchar;
dteTmp date;
begin
--dteGivenDate:='12-03-2004';
dteGivenDate:=$1;
intGivenYear:=date_part('year',timestamp dteGivenDate);
intGivenMonth:=date_part('month',timestamp dteGivenDate);
intNextMonth:=intGivenMonth + 1;
if intNextMonth >12 then
intNextMonth:=1;
intGivenYear:=intGivenYear+1;
end if;
strTmp:= intGivenYear || '-' || intNextMonth || '-' || '10'; -- here we can give any value insted of 10 ranging from (1-28)
dteTmp:= to_date(strTmp,'YYYY MM DD');
dteLastDay:= date dteTmp - 10;
return dteLastDay;
end;
****************
is there any other alternative to this function like a builtin function like last_day ...
sincerely rajesh
---------------------------------
Do you Yahoo!?
vote.yahoo.com - Register online to vote today!
From | Date | Subject | |
---|---|---|---|
Next Message | Gaetano Mendola | 2004-10-03 11:18:27 | Re: Mislabeled timestamp functions (was Re: [SQL] [NOVICE] date_trunc'd |
Previous Message | Madhukar Gole | 2004-10-03 03:12:40 | Help needed to set parameters in postgresql.conf |