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_strings—A 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_Fmt—Specifies the format of the date data in the input variable. Possible values are 1, 2, 3, 4, or 5, as summarized in
Table 16-6: Date Format.
where the asterisk (*) represents one of the following separators: dash (–), slash (/), comma (,), period (.), or colon (:).
Time_Fmt—Specifies the format of the time portion of the data in the input variable. Possible values are –1 or –2, as summarized in
Table 16-7: Time Formats.
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’s 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
For more information on using date/time functions, see the PV‑WAVE User’s Guide.