Post Reply 
(48) DATE->NUM, NUM->DATE, ->EXCELDATE, EXCELDATE->, DTDIFF
05-14-2014, 06:06 PM
Post: #1
(48) DATE->NUM, NUM->DATE, ->EXCELDATE, EXCELDATE->, DTDIFF
I find that the 48 series particularly shines when you write a lot of small utility programs to enhance working within the stack paradigm, and keep them in HOME for access anywhere.

With that in mind, here are a handful of programs that convert dates/times to and from numeric values that are compatible with Excel and Lotus 1-2-3; just format the cell values as dates after transferring the data. I use them a lot within other programs that log time-stamped data.

Converting the times to scalar values rather than formatted values (M.DDYYYY, H.MMSS) has the added benefit of making it easier to plot time-based data directly on the 48.

DATE->NUM
Input:
1: Formatted date

Output:
1: Days since December 30, 1899

Code:
\<< 1.0119 SWAP DDAYS 2 + \>>

NUM->DATE
Input:
1: Days since December 30, 1899

Output:
1: Formatted date

Code:
\<< IP 2 - 1.0119 SWAP DATE+ \>>

->EXCELDATE
Input:
2: Formatted date
1: Formatted time

Output:
1: Excel/Lotus-compatible date value (e.g. right now is 41773.5727104)

Code:
\<< HMS\-> 24 / SWAP DATE\->NUM + \>>

EXCELDATE->
Input:
1: Excel/Lotus date value

Output:
2: Formatted date
1: Formatted time

Code:
\<< DUP IP NUM\->DATE SWAP FP 24 * \->HMS \>>

DTDIFF
Not directly related to the above programs, but worth including here. Gives elapsed time between two date/time pairs.

Input (all formatted values):
4: Starting date
3: Starting time
2: Ending date
1: Ending time

Output:
1: Elapsed time in H.MMSS format

Code:
\<< \-> D1 T1 D2 T2
  \<< D1 D2 DDAYS 24
* T2 T1 HMS- HMS+
  \>>
\>>

Some notes:

The programs use date constants that are equivalent regardless of the current date format (flag -42). That's why there's a fudge factor of 2 days, rather than a flag check, two date constants, and IFTE.

Running ->EXCELDATE EXCELDATE-> in sequence will not return the original starting values. Combining the date and time into a single real number will give you a small amount of rounding error, though the time appears to retain about 8 significant digits after the round trip.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(48) DATE->NUM, NUM->DATE, ->EXCELDATE, EXCELDATE->, DTDIFF - Dave Britten - 05-14-2014 06:06 PM



User(s) browsing this thread: 1 Guest(s)