Date Calculations

This program allows you to calculate the number of days between any 2 given dates. These datse must be later than 15 October 1582, dates before that will result in incorrect answers.
It can also be used to calculate the day of the week of any given date, also later than 15 October 1582. An answer of 0 means it was a Saturday, a 1 is Sunday, all the way to a 6 for Friday.

Answers will only be correct for dates after 15 October 1582 because that's when our current "Gregorian Calendar" was introduced. This calendar assumes a year to be 365.2425 days long, instead of the previously assumed 365.25 days. Because of this ancient error Easter started shifting more and more towards the summer, and we can't have that, can we?
Hats off for the scientists who were able to measure the length of a year at that accuracy considering their backwards understanding of the universe and the lack of precise instruments. They still had to believe that the earth was in the centre of the universe, back then, or they would be invited to a barbecue.

Methods

The trick about these calculations is to convert any given date into a linear number, starting from the 1st of January in the year 0, provided that we had started our current Greogorian calendar from the very beginning. Once you've got this factor for both the starting date and the end date, you can simply subtract the two numbers from each other to get the number of days in between these two dates.
This linear representation of any particular day can also be used to find the day of the week, simply by taking the modulo of 7 from that number. A 0 would then be a Saturday, while a 6 would be a Friday.
The only difficulty would be to calculate this linear representation. I have found these formulas in the Texas Instruments TI-58/59 Master Library manual and converted them to RPN.

For dates in January or February of any year use this formula:

Factor = 365(YYYY) + DD + 31(MM-1) + INT((YYYY-1)/4) - INT(0.75(INT((YYYY-1)/100)+1))

For the rest of the year use this formula:

Factor = 365(YYYY) + DD + 31(MM-1) - INT(0.4MM + 2.3) + INT(YYYY/4) - INT(0.75(INT(YYYY/100)+1))

Both calculations start at LBL 0. The first part of the calculation is the same in both cases, so after calculating 31(MM-1) we decide whether it is January/February, or the rest of the year. And finally the last part of both formulas is almost identical again, the only difference being that for Jan and Feb we need to use YYYY-1, while for the rest of the year we need to use YYYY.
I've used a few RPN tricks to keep the entire calculation on the stack, with only the I register for temporary storage. Therefore the stack and the I register will be completely destroyed after calculating the date factor. For the date difference calculation only storage register 1 is being used for temporary storage.

How To Use The Program

Dates are entered in the form of YYYY.MMDD, where YYYY is a four digit year, MM is a 2 digit month and DD is a 2 digit day of the month. Use leading zeroes to make the month and day 2 digit numbers each. Dates before 15 October 1582 should not be used, they will give wrong answers.
No attempt is made to verify if you have entered a valid date, that would take far too many program steps. It's just a matter of rubbish in, results in rubbish out.

In order to calculate the number of days between two dates enter the oldest date first, then press ENTERπŸ • followed by the youngest date. Then press the A key. After a few seconds you'll see the number of days between these two dates.

In order to calculate the day of the week enter the desired date and press the B key. An answer of 0 means it is a Saturday, a 1 is a Sunday, a 2 is a Monday, a 3 is a Tuesday, a 4 is a Wednesday, a 5 is a Thursday and finally a 6 is Friday.

Some Examples

What day of the week was New Year's day 2000?

2 0 0 0 . 0 1 0 1 B
And the answer is 0, which means it was a Saturday.

How many days were there between 30 July 1958 and 12 December 1959?

1 9 5 8 . 0 7 3 0 ENTERπŸ • 1 9 5 9 . 1 2 1 2 A
And the answer is 500.

And now two examples to verify whether you've entered the program in correctly:

What is the date factor for 15 February 2020? Enter: 2020.0215 and press GSB 0 and the answer should be 737,835.

What is the date factor for 29 March 2022? Enter: 2022.0329 and press GSB 0 and the answer should be 738,608.

The Program

000–
h LBL A001–25 13 11Calculate Date X - Date Y
STO 1002–23 1Save most recent date
X⇋Y003–21
GSB 0004–13 0First calculate factor for oldest date
RCL 1005–24 1
X⇋Y006–21
STO 1007–23 1Save intermediate result
X⇋Y008–21
GSB 0009–13 0Now calculate factor for youngest date
RCL 1010–24 1
–011–41Subtract the two
h RTN012–25 12
 
h LBL B013–25 13 12Calculate Day Of Week (Sat = 0, Fri = 6)
GSB 0014–13 0Calculate date factor
7015–7Get modulo 7
Γ·016–71
h FRAC017–25 33
7018–7
Γ—019–61
β€’020–73Correction for rounding errors
1021–1
+022–51
h INT023–25 32
h RTN024–25 12
 
h LBL 0025–25 13 0Calculate days since 1 Jan Year 0
h INT026–25 32Isolate Year
h LST X027–25 0
h FRAC028–25 33Isolate Month
EEX029–33
2030–2
Γ—031–61
h INT032–25 32
h LST X033–25 0
h FRAC034–25 33Isolate Day
EEX035–33
2036–2
Γ—037–61Z=Year, Y=Month, X=Day
X⇋Y038–21Calculate Day + 31(Month -1)
STO f I039–23 14 23
1040–1
–041–41
3042–3
1043–1
Γ—044–61
+045–51
f R↑046–14 22Multiply Year with 365 and add to subtotal
3047–3
6048–6
5049–5
Γ—050–61
+051–51
f X⇋I052–14 21X=Month, Y=Z=T=Year, I=Year * 365 + Day + 31(Month - 1)
3053–3Jan/Feb is separate from rest of year
f Xβ©½Y054–14 41
GTO 0055–22 0It's the rest of the year
f R↑056–14 22Get Year - 1
1057–1
–058–41
ENTER↓059–31
ENTER↓060–31Calculate INT(Year -1)/4)
4061–4
Γ·062–71
h INT063–25 32
X⇋Y064–21
GTO 1065–22 1Rest is the same for the rest of the year
h LBL 0066–25 13 0Month bigger than February
g R↓067–15 22X=Month, Y=Year
β€’068–73Calculate -(INT(0.4 x Month + 2.3)
4069–4
Γ—070–61
2071–2
β€’072–73
3073–3
+074–51
h INT075–25 32
CHS076–32
X⇋Y077–21Save result in Y and get Year back
ENTER↓078–31Calculate INT(Year/4) and add to previous result
ENTER↓079–31
4080–4
Γ·081–71
h INT082–25 32
X⇋Y083–21
g R↓084–15 22
+085–51
f R↑086–14 22Y=Intermediate result, X=Year
h LBL 1087–25 13 1Calculate INT(Year/100)+1
EEX088–33
2089–2
Γ·090–71
h INT091–25 32
1092–1
+093–51
β€’094–73Now get INT of previous result * 3/4
7095–7
5096–5
Γ—097–61
h INT098–25 32
–099–41Subtract this from previous result
RCL f I100–24 14 23Now add it the first half of calculation
+101–51
h RTN102–25 12Return with factor in X, Stack and I are destroyed
GTO 0103–22 0