Post Reply 
(22s or 27s, 17b, etc) Calculate day of week from 1901 to 2099
02-20-2022, 03:36 PM
Post: #1
(22s or 27s, 17b, etc) Calculate day of week from 1901 to 2099
On the HP 22s, with no branching or loops, little more than equations are possible on it. However, using a creatively written equation, it is possible to calculate the day of the week from 1901 to 2099 and also handle leap years.

To calculate the first day of a year, F, we use the following formula:

F=(IP( 1.25 x (Year + 3)) + 2) mod 7

Since the HP 22s does not have the mod function, we can use:

a mod b = FP( a / b ) x b

So

F=FP( (IP( 1.25 x (Year + 3)) + 2) / 7) x 7

To determine which day each month begins with, we add:

( 530526416330 / 10^(Month-1) ) mod 10 or FP( ( 530526416330 / 10^(Month-1) ) / 10) x 10

Finding if a year is a leap year (0=non leap year, 1=leap year)

1-IP( (y mod 4)/4+.75 ) or 1-IP(FP(y/4)+.75)

Adding an extra day after February for leap years (0 for months 1 and 2, and 1 for months 3 and beyond)

IP(IP(M / 3) / 4 + .75)

Bringing it all together, for the HP 22s (spaces added for ease of viewing)

W=FP( ( IP(1.25 x (Y+3)) + 2 + FP( IP(530526416330 / 10^(M-1)) / 10) x 10 + D - 1 + (1 - IP( FP(Y/4) + .75)) x IP( IP(M/3) / 4 +.75)) /7)x7

Or on the 27s, 17B, etc.:

W=MOD( IP( 1.25 x (Y+3)) + 2 + MOD( IP( 530526416330 / 10^(M-1)):10) + D - 1 + (1-IP( FP(Y/4) +.75)) x IP( IP(M/3)/4+.75):7)

For the number returned, 0=Sunday, 1=Monday, 2=Tuesday … 6=Saturday
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(22s or 27s, 17b, etc) Calculate day of week from 1901 to 2099 - arhtur - 02-20-2022 03:36 PM



User(s) browsing this thread: 1 Guest(s)