Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge: Compute the number of Tuesdays since a given date
#23
Quote:(1)
' 1-1-1900 was a Sunday (backtracked)
NO, IT WAS A MONDAY.
This is caused by my explaination at comment (2).

Quote:(2) IF INT(NowYear / 4) * 4
THIS IS NOT A VERY GOOD WAY TO CHECK FOR LEAP YEAR. FOR EXAMPLE, THIS CODE WOULD CONSIDER 1900 AS A LEAP YEAR, WHICH IT WAS NOT. SEE THË "ISLEAPYEAR" FUNCTION AND COMMENTS AT THE END OF MY POSTED SOLUTION ABOVE.
*****
Hrmm, I thought every year, multiplier of 4 was a leap year. (read your IsLeapYear)... hrmmm... ok right. So 1900 was not... that means 1-1-1900 wasn't a Sunday but a Monday indeed (counted 1 day extra: 29-2-1900). To solve this problem, do this:

Replace:
Code:
IF INT(NowYear / 4) * 4 = NowYear THEN DaysPerMonth(2) = 29 ELSE DaysPerMonth(2) = 28
by:
Code:
IF (NowYear MOD 4 = 0 AND NowYear MOD 100 <> 0) OR (NowYear MOD 400 = 0) THEN DaysPerMonth(2) = 29 ELSE DaysPerMonth(2) = 28
(didn't even know this but I learnt from your function Wink)
Reply


Messages In This Thread
Challenge: Compute the number of Tuesdays since a given date - by Neo - 06-23-2004, 04:54 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)