View previous topic :: View next topic
|
Author |
Message |
naveengonu
New User
Joined: 20 May 2006 Posts: 2 Location: Chennai
|
|
|
|
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 |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
Hi naveengonu,
This link might help you.
Thanks,
Shankar |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
Back to top |
|
|
yogeshwar_ade
Active User
Joined: 31 Aug 2006 Posts: 103 Location: INDIA
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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? |
|
Back to top |
|
|
naveengonu
New User
Joined: 20 May 2006 Posts: 2 Location: Chennai
|
|
|
|
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? |
|
|
Back to top |
|
|
|