Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Zeller's congruence to get day of week
#10
Code: (Select All)
CheckDate = Date$
CheckTime = Time$
If CheckDate <> Date$ Then ' Midnight rolled over
    CheckDate = Date$
    CheckTime = Time$
End If

I don't think the above is going to catch any Midnight roll over for you. Follow along with me and think of this little scenario:

CheckDate = Date$ '23:59.9998 time (HH:MM:SSSS)
CheckTime = Time$ '23:59.9998 time
If CheckDate <> Date$ Then ' 23:59.9999 time ==> OH NOS! TIME DOESN'T MATCH! GET NEW TIME!
    CheckDate = Date$ ' 23:59.9999 time
    CheckTime = Time$ ' 00:00.0000 time <-- Midnight just rolled over between those times!
End If[/code]

As you can see, you're not preventing the Date from falling behind. If it can fall behind after the first CheckDate = Date$ assignment, then why can't it fall behind at the second CheckDate = Date$ assignment?

Seems to me like the only way to do what you're wanting would be to verify the date again before the PRINT statement. Check the CheckDate$ vs Date$ there, and if it's not the same at that point, then redo the process with the new date...

(And yet, that can't catch 100% of all date change errors, as the date might change in the millisecond after that check, and while the PRINT is printing the date...)

Sometimes you just have to shrug and say, "Close enough is close enough."
Reply


Messages In This Thread
RE: Simple Zeller's congruence to get day of week - by SMcNeill - 09-16-2024, 12:16 PM



Users browsing this thread: 3 Guest(s)