IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Logic to find the day given the date


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Jul 10, 2009 3:19 pm
Reply with quote

Click on the following link -

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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jul 16, 2009 7:14 pm
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
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. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Need help to append a date&tsp at... DFSORT/ICETOOL 9
Search our Forums:

Back to Top