Page 1 of 1

LAST_DAY function in db2

Posted: Wed Sep 02, 2009 7:07 am
by sshettar
Hi All,

I have this field which needs to get the month end date of a given date field . i am populating a db2 table. I know db2 does have a function LAST_DAY which would give this result, i tried using this function on Advanced Query Tool , but i'm getting the following error

42884(-440)[IBM][CLI Driver][DB2/AIX64] SQL0440N No authorized routine named "LAST_DAY" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884
(0.19 secs)

Do not know as to why i'm getting this error.

any help in achieving this task would be of great help

Thanks in advance

Re: LAST_DAY function in db2

Posted: Wed Sep 02, 2009 7:15 am
by Sainath.Srinivasan
sshettar wrote: No authorized routine named "LAST_DAY" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884
Appears issue with the arguments passed.

Posted: Wed Sep 02, 2009 7:21 am
by chulett
First person you should take this to, IMHO, is your DBA. That or Google for examples of the proper syntax.

Posted: Wed Sep 02, 2009 9:26 am
by sshettar
I did check with the DBA and he said that the version of DB2 we are using doesnt support the function LAST_DAY.
is there any other way to get the month end date of a given date ?

any helo is highly appreciated

Thanks in advance

Posted: Wed Sep 02, 2009 10:19 am
by chulett
Sorry, my helicopter is in the shop. :wink:

Check this thread: viewtopic.php?t=115051

Posted: Wed Sep 02, 2009 10:37 am
by priyadarshikunal
probably this topic can give you a good start

viewtopic.php?p=338077&highlight=#338077

apart from that you need to add 1 to the month and if its 12 add 1 to year and hard code 01 as month.

Posted: Thu Sep 03, 2009 1:38 am
by Grace J.
Try this, select (given_date +1 month -day(given_date) day) lastday from tablename ;

Posted: Thu Sep 03, 2009 3:54 am
by laknar
select DATE('given_date') +1 month -day(DATE('given_date')) as lastday from tablename

Posted: Thu Sep 03, 2009 8:26 am
by sshettar
Thanks Grace and laknar!!!!

the command worked for me .

Thanks you once again. i'm marking this topic as resolved