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.
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.
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.
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.
000β | |||
h LBL A | 001β | 25 13 11 | Calculate Date X - Date Y |
STO 1 | 002β | 23 1 | Save most recent date |
XβY | 003β | 21 | |
GSB 0 | 004β | 13 0 | First calculate factor for oldest date |
RCL 1 | 005β | 24 1 | |
XβY | 006β | 21 | |
STO 1 | 007β | 23 1 | Save intermediate result |
XβY | 008β | 21 | |
GSB 0 | 009β | 13 0 | Now calculate factor for youngest date |
RCL 1 | 010β | 24 1 | |
β | 011β | 41 | Subtract the two |
h RTN | 012β | 25 12 | |
h LBL B | 013β | 25 13 12 | Calculate Day Of Week (Sat = 0, Fri = 6) |
GSB 0 | 014β | 13 0 | Calculate date factor |
7 | 015β | 7 | Get modulo 7 |
Γ· | 016β | 71 | |
h FRAC | 017β | 25 33 | |
7 | 018β | 7 | |
Γ | 019β | 61 | |
β’ | 020β | 73 | Correction for rounding errors |
1 | 021β | 1 | |
+ | 022β | 51 | |
h INT | 023β | 25 32 | |
h RTN | 024β | 25 12 | |
h LBL 0 | 025β | 25 13 0 | Calculate days since 1 Jan Year 0 |
h INT | 026β | 25 32 | Isolate Year |
h LST X | 027β | 25 0 | |
h FRAC | 028β | 25 33 | Isolate Month |
EEX | 029β | 33 | |
2 | 030β | 2 | |
Γ | 031β | 61 | |
h INT | 032β | 25 32 | |
h LST X | 033β | 25 0 | |
h FRAC | 034β | 25 33 | Isolate Day |
EEX | 035β | 33 | |
2 | 036β | 2 | |
Γ | 037β | 61 | Z=Year, Y=Month, X=Day |
XβY | 038β | 21 | Calculate Day + 31(Month -1) |
STO f I | 039β | 23 14 23 | |
1 | 040β | 1 | |
β | 041β | 41 | |
3 | 042β | 3 | |
1 | 043β | 1 | |
Γ | 044β | 61 | |
+ | 045β | 51 | |
f R↑ | 046β | 14 22 | Multiply Year with 365 and add to subtotal |
3 | 047β | 3 | |
6 | 048β | 6 | |
5 | 049β | 5 | |
Γ | 050β | 61 | |
+ | 051β | 51 | |
f XβI | 052β | 14 21 | X=Month, Y=Z=T=Year, I=Year * 365 + Day + 31(Month - 1) |
3 | 053β | 3 | Jan/Feb is separate from rest of year |
f Xβ©½Y | 054β | 14 41 | |
GTO 0 | 055β | 22 0 | It's the rest of the year |
f R↑ | 056β | 14 22 | Get Year - 1 |
1 | 057β | 1 | |
β | 058β | 41 | |
ENTER↓ | 059β | 31 | |
ENTER↓ | 060β | 31 | Calculate INT(Year -1)/4) |
4 | 061β | 4 | |
Γ· | 062β | 71 | |
h INT | 063β | 25 32 | |
XβY | 064β | 21 | |
GTO 1 | 065β | 22 1 | Rest is the same for the rest of the year |
h LBL 0 | 066β | 25 13 0 | Month bigger than February |
g R↓ | 067β | 15 22 | X=Month, Y=Year |
β’ | 068β | 73 | Calculate -(INT(0.4 x Month + 2.3) |
4 | 069β | 4 | |
Γ | 070β | 61 | |
2 | 071β | 2 | |
β’ | 072β | 73 | |
3 | 073β | 3 | |
+ | 074β | 51 | |
h INT | 075β | 25 32 | |
CHS | 076β | 32 | |
XβY | 077β | 21 | Save result in Y and get Year back |
ENTER↓ | 078β | 31 | Calculate INT(Year/4) and add to previous result |
ENTER↓ | 079β | 31 | |
4 | 080β | 4 | |
Γ· | 081β | 71 | |
h INT | 082β | 25 32 | |
XβY | 083β | 21 | |
g R↓ | 084β | 15 22 | |
+ | 085β | 51 | |
f R↑ | 086β | 14 22 | Y=Intermediate result, X=Year |
h LBL 1 | 087β | 25 13 1 | Calculate INT(Year/100)+1 |
EEX | 088β | 33 | |
2 | 089β | 2 | |
Γ· | 090β | 71 | |
h INT | 091β | 25 32 | |
1 | 092β | 1 | |
+ | 093β | 51 | |
β’ | 094β | 73 | Now get INT of previous result * 3/4 |
7 | 095β | 7 | |
5 | 096β | 5 | |
Γ | 097β | 61 | |
h INT | 098β | 25 32 | |
β | 099β | 41 | Subtract this from previous result |
RCL f I | 100β | 24 14 23 | Now add it the first half of calculation |
+ | 101β | 51 | |
h RTN | 102β | 25 12 | Return with factor in X, Stack and I are destroyed |
GTO 0 | 103β | 22 0 |