MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to find if last month has 30 or 31 days from the current

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
misi
Beginner


Joined: 14 Apr 2004
Posts: 13
Topics: 10

PostPosted: Wed Apr 21, 2004 11:48 am    Post subject: how to find if last month has 30 or 31 days from the current Reply with quote

I have a program which should generate monthly report. The report can be run on any day of the month. The SQl query should retrieve all records which has been inserted for the last 1 month from the current date. A timestamp field is present in the table. How do I write the query to retrieve the last 1 months data If i run the query on any day of the month. Last month can have 30 or 31 days or 28 or 29 days..So accordingly my query should calculate the start date and obviously the end date is the current date.

misi
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Wed Apr 21, 2004 11:56 am    Post subject: Reply with quote

Misi,

If you are using DB2 Version 7 then you can use the function LAST_DAY to get the last day of every month

Code:

SELECT LAST_DAY(CURRENT DATE - 1 MONTH)
  FROM SYSIBM.SYSDUMMY1;


Check this link for a detailed explanation of LAST_DAY scalar function.

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH10/3.2.40?SHELF=&DT=20010215120247&CASE=

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group