Since date functions and calendar programs seem to be en vogue these days, here is my contribution for the HP35s. It is essentially a small program that converts between common calendar dates and Julian day numbers. This allows for all essential date related functions:

Determining the weekday for a given date

Calculating the difference between two dates in days

Adding/subtracting a number of days to/from a given date

Checking dates for validity

The following program works with Julian day numbers (JDNs). As opposed to the familiar notation with day, month and year, JDNs are simple consecutive numbers. Every day has a unique JDN, and 100 days later the JDN has increased by 100 as well - it's as simple as that. The day count starts with day 0 being 1 Jan 4713 B.C., and the last day the program handles is 31 Dec 9999 which is JDN 5373484. The switch from the older Julian to the current Gregorian calender is implemented in that Thu 4 Oct 1582 is directly followed by Fri 15 Oct 1582. You may may change this to a different date, for instance if in your region the switch occured later - see below.

You can now imagine that JDNs make date related calculations very easy - as they are plain integers you can use simple addition and subtraction. Dividing a JDN by 7 yields a remainder that stands for the weekday of that date. Here is a program that does all this. Just to be sure: of course RPN mode is assumed. And be sure not to confuse x<>y (exchange stack registers x and y) and x<> Y (exchange x and variable Y).

This is what you see in FIX 6 display mode. You may also use ALL, but since trailing zeroes are ommited, dates like 1 Jul 1980 will appear as 1,07198 or 15 Aug 2000 will be displayed as 15.082.

The program uses Flag 0 - please see below at the section on using a proleptic Julian calendar.The following examples assume that Flag 0 is cleared.

Date calculations

The program converts dates both from and to Julian day numbers (JDNs). Any integer input is considered a JDN, and everything with a fractional part is assumed to be a date in dd.mmyyyy format. The program returns two results: the JDN resp. date in X as well as the corresponding weekday in Y. Here 1 = Monday ... 7 = Sunday.

23,081999 [XEQ] N [ENTER] 1 // 23 Aug 1999 was a Monday
235 // and the 235th day of the year

Forcing a proleptic Julian calendar

Unless flag 0 is set, the program assumes that the Julian calendar was used until 4 Oct 1582 as stated in Inter gravissimas by Gregory XIII. Using this date for the switch from Julian to Gregorian is common practice. However, many regions in the world changed later, some not before the 20th century.

Setting Flag 0 now enables a proleptic Julian calendar, i.e. it assumes this calendar was valid for any given date. This allows some useful applications.

1. Converting between Julian and Gregorian calendar

The October Revolution started on 7 Nov 1917. What date was this in the Julian calender used those days in Russia?

Johann Sebastian Bach was born on 21 March 1685 according to the Julian calendar which was still valid in his region. Later the Gregorian calendar was adopted. On which day may Bach have celebrated his birthday after the switch?

The original program assumes the Julian calendar was valid until Thu 4 Oct 1582 which was directly followed by Fri 15 Oct 1582 as the first day of the Gregorian calendar. This is hardcoded by the constant 2299160 in line J040 and J072. It is the JDN of the last day of the Julian calendar, i.e. the JDN of 4 Oct 1582.

If you live in a region where the Gregorian calendar was adopted later, you may want to reflect your local situation by using a different transition point. For instance, Britain and its colonies (including the US) switched after 2 Sep 1752 (followed by 14 Sep 1752). Adjusting the program accordingly is easy:

Using the unmodified program, you can try the same with 4 Oct 1582 (adding a day will yield 15 Oct 1582) and an invalid date like 10 Oct 1582 (will return 2299156 and 2299166).

Checking dates

The program does not perform any checks to make sure the user entered a valid date, i.e. you may enter 35 Mar 1975 without an error message although March has only 31 days. In this case the program will return the JDN for 4 Apr 1975. This can be used for a simple validity test: simply convert a date to its JDN and back again. If the result matches the original entry, the date was valid.