Following are a set of sunrise/sunset programs that I have developed for the HP41/HP42/HP33S/HP35S calculators. Comments are suggestions are welcome.

HP-41C and HP42S (with modifications to date routines) program to display sunrise / sunset for a given date

Usage:

Using local labels:

A = sunrise sunset for today (not available on HP42S since this routine assumes that availability of a Time module)
B = sunrise / sunset for tomorrow (not available on HP42S since this routine assumes that availability of a Time module)
C = sunrise / sunset for date in X register. Date should be provided in current DMY / MDY format either as dd.mmyyyy or
as mm.ddyyyy respectively. Correct handling for dates in either format is dependent on the DOY routine presented
in this article.
D = Flip daylight savings time mode. Flag 01 clear = standard time / Flag 01 set = daylight savings time.
E = Flip display mode. Flag 00 clear = single line display / Flag 00 set = multiline display

After running the program the following results are on the stack.

Z: Sunset time
Y: Sunrise time
X: Length of day

===============================================================================================
Main HP41C program

===============================================================================================
DOY (Day Of Year) routine used by the HP41C version. Note that as mentioned elsewhere the 41C
version assumes that a Time module is available.

If desired item 4 can be easily retrofitted to the 33S and 35S versions. However, it is probably easier
to simply have the user manually set a flag rather than have a short routine to do so.

If desired this program can be cut back to the functionality of the 33S and 35S versions. This might be
desirable if memory space is at a premium. The features above can all be removed relatively easily.

1. Sunrise / sunset for today: Remove LBL A. Code between lines 02 and 04 inclusive.
2. Sunrise / sunset for tomorrow: Remove LBL B. Code between lines between 05 and 08 inclusive.
3. If both changes above are made LBL 03 (line 10) can be removed. With these changes it
might also make sense to replace LBL C with LBL A or remove local labels completely.
4. The logic controlling the display of results is contained in lines 32-61 inclusive. Choose
either approach or neither and just leave the results on the stack. The logic that calculates
the day length is also included in this code. This is calculated in both display routines.
If this logic is to be retained keep either the set of lines 40-42 or the lines 56-58.
5. If one or both display options are removed also remove the logic that switches between them.
This is LBL E and can be found at lines 173-175. It is also possible to keep the display
options but remove this code and set flag 00 manually.
6. If the logic that handles Daylight Savings Time is not needed it can also be removed.
The code can be found at lines 163-166.
7. If the DST logic is removed also remove the logic that switches between standard time and DST.
This is LBL D and can be found at lines 169-172. As with the display option selection code this
selection code can be removed and flag 01 can be set manually.

A further optional improvement may be added. If you want to see the date for which sunrise / sunset
times are being calculated add the following code right after LBL 03:

===============================================================================================
Following are versions for the HP33S and HP35S. Note that both version require the date routines at the bottom of this article.

===============================================================================================
Programs for HP33S single label followed by short form

There are two routines included here.
LBL X takes a date in the form of MM.DDYYYY and returns the day number for the year.
LBL Y takes two dates (MM.DDYYYY in X and Y and returns the number of days between them.