STR_TO_DT Function

Converts date and time string data to date/time values.

Usage

result = STR_TO_DT(date_strings[, time_strings])

Input Parameters

date_stringsA string constant or string array that contains date strings.

time_strings(optional) A string constant or string array that contains time strings.

Returned Value

result—A date/time variable containing the converted date/time data.

Keywords

Date_FmtSpecifies the format of the date data in the input variable. Possible values are 1, 2, 3, 4, or 5, as summarized in Date Format.

Date Format

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 (:).

Time_FmtSpecifies the format of the time portion of the data in the input variable. Possible values are –1 or –2, as summarized in Time Formats.

Time Formats

Value

Format Description

Examples for 1:30 p.m.

–1

HH*Mn*SS[.SSSS]

13:30:35.25

–2

HHMn

1330

where the asterisk (*) represents one of the following separators: dash (–), slash (/), comma (,), or colon (:). No separators are allowed between hours and minutes for the –2 format. Both hours and minutes must occupy two spaces.

For a detailed description of the date and time formats, see the PV‑WAVE User Guide.

Note:

Date and time separators are specified with the !Date_Separator and !Time_Separator system variables. The STR_TO_DT function only recognizes the standard separators listed above. If any other separator is specified, this function does not work as expected.

Discussion

You can convert just date strings, just time strings, or both. If you do not pass in a date string, the resulting date portion of the date/time structure defaults to the value in the system variable !DT_Base. If you do not pass in a time string, the time portion of the resulting date/time variable defaults to zero.

Example 1

; Create an array that contains some date strings with
; the MM DD YY date format. 
x = ['3-13-92', '4-20-83', '4-24-64'] 
; Create an array that contains some time strings with
; the HH Mn SS date format. 
y = ['1:10:34', '16:18:30', '5:07:25'] 
; Use the formats 1 and -1 to create the date/time data. 
date1 = STR_TO_DT(x, y, Date_Fmt=1, Time_Fmt =-1) 
DT_PRINT, date1 
; PV-WAVE prints:
; 03/13/1992   01:10:34.000
; 04/20/1983   16:18:30.000
; 04/24/1964   05:07:25.000

Example 2

date2 = STR_TO_DT('3-13-92', Date_Fmt=1)
PRINT, date2
; PV-WAVE prints: { 1992 3 13 0 0 0.00000 87474.000 0 }

See Also

DT_TO_STR, JUL_TO_DT, SEC_TO_DT, VAR_TO_DT

For more information on using date/time functions, see the PV‑WAVE User Guide.