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 

Find no: leap years/christmas days between 2 Dates

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


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Mon Nov 07, 2005 4:04 pm    Post subject: Find no: leap years/christmas days between 2 Dates Reply with quote

Hai All,

1.I am interested in a query wherin i can retreive the information as to how many times(number) of leap years occured during a particular period say 1976-05-04 till 2005-11-08.

2.I am interested in a query wherin i can retreive the information as to how many times the festival of Christmas has occured duing a particular period say 1976-05-04 till 2005-11-08.
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Nov 07, 2005 6:14 pm    Post subject: Reply with quote

Shekhar123,

To find the no: of christmas between a range of dates is easy. Since christmas comes every year, it is just the difference between the two dates in terms of years.The result of subtracting one date (DATE2) from another (DATE1) is a date duration that specifies the number of years, months, and days between the two dates. The data type of the result is DECIMAL(8,0). However you need to consider the current year if the date falls before christmas, it cannot be counted into the total. Similary the beginning date.

Here is an untested sql which I think will give you the no: of christmas days between 2 dates.

Code:

SELECT INT(SUBSTR(DIGITS(                                   
           DATE(CURRENT DATE) - DATE('1976-05-04')),1,4)) - 
           INT(CASE WHEN MONTH(CURRENT DATE) = 12 AND       
                           DAY(CURRENT DATE) > 24           
                    THEN 0 ELSE 1 END) -                     
           INT(CASE WHEN MONTH(DATE('1976-05-04')) = 12 AND 
                           DAY(DATE('1976-05-04')) > 25     
                    THEN 1 ELSE 0 END)                       
  FROM SYSIBM.SYSDUMMY1;                                     


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
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Mon Nov 07, 2005 11:15 pm    Post subject: Reply with quote

The query worked perfectly.

The answer is 28.
Back to top
View user's profile Send private message Send e-mail
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Nov 08, 2005 2:10 am    Post subject: Reply with quote

Kolusu,

Quote:

Here is an untested sql


Do You really need to test a piece of code Question Question Question You have an internal "Mega Mainframe" processor Exclamation Exclamation Exclamation already built inside your head. Very Happy

Thanks,
Phantom
Back to top
View user's profile Send private message
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Wed Nov 09, 2005 8:09 am    Post subject: Reply with quote

1.1: Leap Years:

Problem can be solved with an lookuptable with two columns:

COL1: YEAR, fill table with all possible YEAR
COL2: Indicator, LEAP Year, YES / NO.

It dosn't look like a problem, which can be solved by a single select without the mentioned lookup table.
Back to top
View user's profile Send private message
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