Date/time programs for the HP 35s



#2

Hello everybody.

Here are a few date/time calculation programs for the HP 35s, which some people might find useful. Various formats can be converted to the date/time format used by most spreadsheet programs (days since 31.12.1899) to simplify further calculations, and converted back again.

Programming principles: (1) Input is not needlessly validated; GIGO applies. (2) X gets replaced with the result, and LastX gets set. (3) Variables I and J and indirect registers 0..4 are not preserved. (4) Other stack levels and variables are preserved, except where stated.

Instructions are grouped here to illustrate the logical structure of the programs. I'm sure the code could be made more efficient in places; that's left as an exercise for the reader :-).

Any problems, let us know.

R.

--------------------------------------------------------------------------------------------------------------------------------------------------------

C     ##### time (D.HHMMSSs) -> days #####                                LN=53 CK=BC05
LBL C
XEQ Z002 save stack
STO J FP 100 x HMS-> 24 ÷ RCL J IP + STO J
XEQ Z031 x<>J restore stack
RTN

M ##### days -> time (D.HHMMSSs) ##### LN=53 CK=B214
LBL M
XEQ Z002 save stack
STO J FP 24 x ->HMS 100 ÷ RCL J IP + STO J
XEQ Z031 x<>J restore stack
RTN

T ##### Spreadsheet time -> UTC time (YYYYMMDD.HHMM) ##### LN=560 CK=869E (writes vars R,X)
LBL T
XEQ Z002 STO X save stack
20000101 STO R init calculated time to 2000 start
36526 STO-X ,,
T008 RCL X x>=0? GTO T021 if 2000 or later, skip
10000 STO-R 365 STO+X RCL R 10000 INT÷ XEQ Z052 STO+X add days to X, take years from R
GTO T008
T021 365 STO Q RCL R 10000 INT÷ XEQ Z052 + STO Q RCL X x<y? GTO T037 take days from X, add years to R
RCL Q STO-X 10000 STO+R ,,
GTO T021 ,,
T037 RCL X 31 x>y? GTO T126 STO-X 100 STO+R take days from X, add months to R
RCL X 28 RCL R 10000 INT÷ XEQ Z052 + x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 30 x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 30 x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 30 x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 30 x>y? GTO T126 STO-X 100 STO+R ,,
RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,,
T126 RCL X IP STO-X STO+R move remaining days to R
24 STOxX convert X to hours
RCL X IP 100 ÷ STO+R RCL X FP STO X move hours to R
60 STOxX convert X to mins
RCL X 10000 ÷ STO+R move mins to R
XEQ Z031 x<>R restore stack
RTN

U ##### Unix time -> Spreadsheet time ##### LN=28 CK=AA0E
LBL U 86400 ÷ 25569 + RTN

V ##### UTC time (YYYYMMDD.HHMM) -> Spreadsheet time ##### LN=479 CK=4B0A (writes vars M,R,X)
LBL V
XEQ Z002 STO X save stack
36526 STO R init calculated time to 2000 start
RCL X FP 100 x HMS-> 24 ÷ STO+R add hours÷mins
RCL X 10000 INT÷ STO M get year
V018 2000 RCL M x>=y? GTO V029 calc days from year start to 2000 start
XEQ Z052 STO-R 365 STO-R ,,
1 STO+M GTO V018 ,,
V029 1 STO-M 2000 RCL M x<y? GTO V040 calc days from 2000 start to year start
XEQ Z052 STO+R 365 STO+R ,,
GTO V029 ,,
V040 RCL X 10000 ÷ FP 100 x IP STO M get month
1 RCL M x=y? GTO V119 31 STO+R calc days to start of month
2 RCL M x=y? GTO V119 28 STO+R RCL X 10000 INT÷ XEQ Z052 STO+R ,,
3 RCL M x=y? GTO V119 31 STO+R ,,
4 RCL M x=y? GTO V119 30 STO+R ,,
5 RCL M x=y? GTO V119 31 STO+R ,,
6 RCL M x=y? GTO V119 30 STO+R ,,
7 RCL M x=y? GTO V119 31 STO+R ,,
8 RCL M x=y? GTO V119 31 STO+R ,,
9 RCL M x=y? GTO V119 30 STO+R ,,
10 RCL M x=y? GTO V119 31 STO+R ,,
11 RCL M x=y? GTO V119 30 STO+R ,,
V119 RCL X 100 ÷ FP 100 x IP 1 - STO+R add days in current month
XEQ Z031 x<>R restore stack
RTN

W ##### Spreadsheet time -> weekday (1..7, Sunday = 1) ##### LN=197 CK=8390
LBL W
XEQ Z002 save stack
SF10 print messages
IP 1 - 7 RMDR 1 + STO J
1 x!=y? GTO W016 EQN "SU" PSE GTO W054
W016 RCL J 2 x!=y? GTO W023 EQN "MO" PSE GTO W054
W023 RCL J 3 x=y? GTO W030 EQN "TU" PSE GTO W054
W030 RCL J 4 x=y? GTO W037 EQN "WE" PSE GTO W054
W037 RCL J 5 x=y? GTO W044 EQN "TH" PSE GTO W054
W044 RCL J 6 x=y? GTO W051 EQN "FR" PSE GTO W054
W051 RCL J EQN "SA" PSE
W054 XEQ Z031 x<>J restore stack
RTN

Z ##### various subroutines ##### LN=243 CK=1944
LBL Z
Z002 STO J save stack
RDN 0 STO I RDN RCL J STO(I) ,,
RDN 1 STO I RDN STO(I) ,,
RDN 2 STO I RDN STO(I) ,,
RDN 3 STO I RDn STO(I) ,,
4 STO I RDN 1 STO(I) ,,
XEQ Z031 ,,
RTN ,,
Z031 0 STO I 0 RCL(I) + restore stack
3 STO I RCL(I) ,,
2 STO I RDN RCL(I) ,,
1 STO I RDN RCL(I) ,,
0 STO I RDN RCL(I) ,,
RTN ,,
Z052 STO I is leap year? (0/1)
4 RMDR x!=0? GTO Z069 ,,
RDN RCL I 400 RMDR x=0? GTO Z072 ,,
RDN RCL I 100 RMDR x!=0? GTO Z072 ,,
Z069 RDN 0 RTN ,,
Z072 RDN 1 RTN ,,


Edited: 3 Oct 2013, 4:33 p.m.


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP Prime: Lists in programs Alberto Candel 7 456 12-04-2013, 02:16 AM
Last Post: Alberto Candel
  Prime: how to detect date format giancarlo 1 189 12-02-2013, 11:21 AM
Last Post: Michael de Estrada
  HP Prime: matrices in programs, in need of help Alberto Candel 9 446 11-26-2013, 01:33 AM
Last Post: cyrille de Brébisson
  [HP Prime]How to get Discrete-Time Fourier Transform uklo 0 216 11-18-2013, 08:02 PM
Last Post: uklo
  Grouping programs on the HP Prime Michael de Estrada 11 514 11-04-2013, 01:38 PM
Last Post: Damien
  Date/time formats R. Pienne 4 302 11-01-2013, 12:43 PM
Last Post: Marcus von Cube, Germany
  How to set the Date.Time etc on a WP34S Harold A Climer 4 285 10-29-2013, 09:32 PM
Last Post: FORTIN Pascal
  Prime: Exam mode (possible duplicate after funny response first time) Paul Townsend (UK) 1 171 10-24-2013, 03:09 PM
Last Post: Tim Wessman
  Transfering HP-85A Programs Gerry Schultz 5 278 10-17-2013, 12:30 PM
Last Post: Philip Reagan (Texas)
  New HP 35S Programs posted on my blog Eddie W. Shore 2 164 06-08-2013, 03:47 PM
Last Post: Glenn Shields

Forum Jump: