View Raw SPL
/****************************************************************************
* *
* DT2EXCEL.SPL Copyright 2021 (C) DSP Development Corporation *
* *
* Author: Randy Race *
* *
* Synopsis: Converts Julian date and seconds to EXCEL timestamps *
* *
* Revisions: 18 Jan 2021 RRR Creation *
* *
****************************************************************************/
#if @HELP_DT2EXCEL
DT2EXCEL
Purpose: Converts Julian date and clock seconds to EXCEL timestamps.
Syntax: DT2EXCEL(date, time)
date - Optional. A string or integer julian date, the input date.
Defaults to the current date.
time - Optional. A string or real TOD, the input time. Defaults
to the current time.
Returns: A scalar or series of Excel timestamps
Example:
edt = dt2excel("1-1-2021", "12:00:00");
dte = excel2dt(edt);
edt = 44197.5
dte = "1/1/2021 12:00:00.000"
Example:
W1: {julstr("1-1-1999"), julstr("1-10-1999"), julstr("4-2-1999")}
W2: {todstr("12:00"), todstr("14:00"), todstr("9:35")}
W3: dt2excel(w1, w2)
W4: excel2dt(w3)
W3 == {36161.5, 36170.583333, 36252.399306}
W4 contains the date and time values:
01/01/1999 12:00:00.000
01/10/1999 14:00:00:000
04/02/1999 9:35:00.000
Remarks:
An EXCEL timestamp is a real value that represents the
number of days that have elapsed since 12-30-1899. The
integer part is the whole number of days and the
fractional part is the fraction of a day.
See EXCEL2DT to convert an Excel timestamp to a
Julian date and clock time value.
See Also:
DT2UNIX
DTXY
EXCEL2DT
JULSTR
LOCAL2UTC
STRJUL
STRTOD
TODSTR
UNIX2DT
UTC2LOCAL
XYDT
#endif
/* convert date and time to excel timestamp */
dt2excel(date = getdate(), time = gettime(13), startdate = "1899/12/30")
{
local xldt;
(date, time, startdate) = dt2_parse_args(date, time, startdate);
/* excel timestamps for each pair of date/time columns */
xldt = dt2excel_iterate(date, time, startdate);
return(xldt);
}
ITERATE dt2excel_iterate(date, time, startdate)
{
local xldt;
/* excel date offset */
xldt = date - julstr(startdate) + time / 86400;
return(xldt);
}