Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Logic to find the day given the date

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
naveengonu

New User


Joined: 20 May 2006
Posts: 2
Location: Chennai

PostPosted: Fri Jul 10, 2009 11:08 am    Post subject: Logic to find the day given the date
Reply with quote

Hi All,

I checked the programs in our forum and could find the O/P of 'FIND THE DAY OF ANY INPUT DATE" as incorrect. I/P is

1981/05/06 and O/P is thursday. If you think this as yyyy/mm/dd answer is wednesday or if think like yyyy/dd/mm

answer is Friday. I don't want to point the wrong answer I want to share special quick logic (Or) you can call as

trick.

If you think date as CCYY/MM/DD
Step 1) Left round(YY/4) = S1 (result of Step1)
Step 2) YY+s1+DD = S2 (result of Step2)
Step 3) Just take this codes 144025036146 (So code of Jan is 1, feb is 4, Mar 2 ... nov is 4 and dec is 6).
S2 + (Code of MM) = S3 (result of Step3)
Step 4) S4 = Remainder of (S3/7)

Answer: If you get S4 as 1 it is sunday, 2 is monday, 3 tuesday, 4 wednesday, 5 thursday, 6 friday and 0 saturday.

Note1: For Leap year and if Months are Jan and Feb. Substract 1 at the final.

Note2: Above logic is valid for 1900-99. If you want for 1800-99 (Add 2 to final result), 1700-99(Add 4 to final

result) and 1600-99(Add 6 to final result).

So 2000-99 (Add 6), 2100-99 (Add 4), 2200-99(Add 2) and 2300-99(Add 0).

Hint is calendar will same for all 400 years. I hope I confused you all...

Calc for example: 1981/06/16
S1 = Round(81/4) = 20
S2 = 81+20+16 = 117
S3 = 117+5(Code of June) = 122
S4 = Remainder(122/7) = 3 (Tuesday)

Take todays date 2009/07/10

S1 = Round(09/4) = 2
S2 = 2+9+10 = 21
S3 = 21+0(Code of July) = 21
S4 = Remainder(21/7) = 0 (Again as this 2000-99 add 6 then S4 = 0+6) -----> S4 = 6(Friday)

Try this and let me know if it work for you.
Back to top
View user's profile Send private message

shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Fri Jul 10, 2009 3:13 pm    Post subject:
Reply with quote

Hi naveengonu,

This link might help you.

Thanks,
Shankar
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Jul 10, 2009 3:19 pm    Post subject: Reply to: Logic to find the day given the date
Reply with quote

Click on the following link -

http://ibmmainframes.com/viewtopic.php?p=191303&highlight=#191303

Regards,
Back to top
View user's profile Send private message
yogeshwar_ade

Active User


Joined: 31 Aug 2006
Posts: 103
Location: INDIA

PostPosted: Thu Jul 16, 2009 5:30 pm    Post subject:
Reply with quote

Naveen,

I have tried for 2009/07/16 but it's failing

Step 1) Left round(YY/4) = S1 (result of Step1) = 02
Step 2) YY+s1+DD = S2 (result of Step2) = 27
Step 3) Just take this codes 144025036146 (So code of Jan is 1, feb is 4, Mar 2 ... nov is 4 and dec is 6).
S2 + (Code of MM) = S3 (result of Step3) = 27
Step 4) S4 = Remainder of (S3/7) = 6

As it's 2009 , so adding 6 to it gain which comes to be 12 which is out of your range given.....


Awaiting for your reply.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jul 16, 2009 7:14 pm    Post subject: Reply to: Logic to find the day given the date
Reply with quote

Did you click on the above link and try the code provided?

The date needs to be in CCYYMMDD format (no edit characters).

Why reinvent the wheel? icon_rolleyes.gif
Back to top
View user's profile Send private message
naveengonu

New User


Joined: 20 May 2006
Posts: 2
Location: Chennai

PostPosted: Wed Mar 24, 2010 9:00 pm    Post subject: Re: Reply to: Logic to find the day given the date
Reply with quote

Hi Bill,

Your suggestion is very great for me programmatically, I accept this suggestion. I was just sharing this where you can do the calculation in your mind..

Regards
Naveen.G

Bill O'Boyle wrote:
Did you click on the above link and try the code provided?

The date needs to be in CCYYMMDD format (no edit characters).

Why reinvent the wheel? icon_rolleyes.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts To find out size allocated to a seque... ashek15 JCL & VSAM 15 Thu Apr 27, 2017 9:42 am
No new posts LISTIDR compiled date/time jerryte IBM Tools 3 Thu Apr 20, 2017 7:37 pm
No new posts SUBSTR for Date functions Shaheen Shaik DB2 4 Thu Apr 06, 2017 2:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us