DT_TO_SEC Function

Standard Library function that converts a date/time variable to a double-precision variable containing number of seconds elapsed from a base date.

Usage

  • result = DT_TO_SEC(dt_var)

Input Parameters

dt_var — A date/time variable.

Returned Value

result — A double-precision variable containing the number of seconds elapsed between the base date and the date(s) contained in dt_var. The value of the base date is maintained in the system variable !DT_Base.

Keywords

Base — A string containing a date, such as “3-27-92”. This is the base date from which the number of elapsed seconds is calculated. Base can be used to override the default value in the system variable !DT_Base.

Date_Fmt — Specifies the format of the base date, if passed into the function. Possible values are 1, 2, 3, 4, or 5, as summarized in Possible Date_Fmt Values:

Possible Date_Fmt Values

Value

Format Description

Examples for May 1, 1992

1

MM*DD*[YY]YY

05/01/92

2

DD*MM*[YY]YY

01-05-92

3

ddd*[YY]YY]

122,1992

4

DD*mmm[mmmmmm]*[YY]YY

01/May/92

5

[YY]YY*MM*DD

1992-05-01

where the asterisk (*) represents one of the following separators: dash (–),
slash (/), comma (,), period (.), or colon (:).

For a detailed description of these formats, see the PV‑WAVE User Guide.

Discussion

This function is useful for converting date/time values to relative time. The default base date is September 14, 1752.

Example 1

Assume that you have created the array date1 that contains the following date/time data:

date1 = [{!DT, 2002,3,27,7,18,57.0000,91140.305,0},$
         {!DT, 2003,3,27,7,18,57.0000,91505.305,0}, $
         {!DT, 2004,3,27,7,18,57.0000,91871.305,0}]
; To find out the number of seconds for each date from
; the default base, September 14, 1752, use:
seconds = DT_TO_SEC(date1)
PRINT, seconds, Format='(F15.1)'
; PV-WAVE prints:
;   7874435937.0
;   7905971937.0
;   7937594337.0

Example 2

Assume that you have created the array date1 that contains the following date/time data:

date1 = [{!DT, 2002,3,27,7,18,57.0000,91140.305,0},$
         {!DT, 2003,3,27,7,18,57.0000,91505.305,0}, $
         {!DT, 2004,3,27,7,18,57.0000,91871.305,0}]
; To find out the number of seconds for each date from 
; January 1, 1970, use:
seconds = DT_TO_SEC(date1, Base='1-1-70', Date_Fmt=1)
PRINT, seconds, Format='(F15.1)'
; PV-WAVE prints the following:
;   1017213537.0
;   1048749537.0
;   1080371937.0

See Also

DT_TO_STR, DT_TO_VAR, SEC_TO_DT

System Variables: !DT_Base

For more information, see the PV‑WAVE User Guide.