User Guide > Working with Date/Time Data > Converting Your Data into Date/Time Data
  

Converting Your Data into Date/Time Data
If you are importing date/time data into PV‑WAVE, four functions simplify converting this data into date/time data. These functions are:
*STR_TO_DT—Converts string data or variables containing string data into date/time variables.
*VAR_TO_DT—Converts numeric variables containing date/time information into date/time variables.
*SEC_TO_DT—Converts seconds into date/time variables.
*JUL_TO_DT—Converts the Julian day into a date/time variable.
Error checking is performed by these functions to verify that numbers assigned to the date/time structure elements fall within valid ranges. For more information about these functions, see PV‑WAVE Reference.
 
note
If you read and converted your data with the DC_READ routines, you do not need to use these functions to convert your data.
STR_TO_DT Function
This function converts date and time data stored as strings into date/time variables. The function has the form:
result = STR_TO_DT(date_strings[, time_strings]) 
The Date_Fmt and Time_Fmt keywords are used to describe the format of the input string data by specifying a template to use as the data is read. These templates are listed in Valid Date Formats for STR_TO_DT Function.
 
Table 8-2: Valid Date Formats for STR_TO_DT Function  
Keyword Value
Template 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-01-01
The abbreviations used in the template descriptions are:
MM—The numerical month. The month does not need to occupy two spaces. For example, you can enter a 1 for the month of January.
DD—The numerical day of the month. The day does not need to occupy two spaces. For example, for May 5, the numerical day can be 5.
[YY]YY—The numerical year. For example, 1992 can be entered as 92 or 1992.
ddd æ The numerical day of the year. The day does not need to occupy three spaces. For example, February 1 is 32.
mmm[mmmmmm]—The full name of the month or its abbreviation depending on how the system variable !Month_Names is set.
* —Represents a delimiter that separates the different fields of data. The delimiter can also be a slash (/), a colon (:), a hyphen (–), period (.), or a comma (,).
 
Table 8-3: Valid Time Formats for STR_TO_DT Function  
Keyword
Value
Template Description
Examples for
1:30 p.m.
–1
HH*Mn*SS[.SSS]
13:30:35.25
–2
HHMn
No separators are allowed between hours and minutes. Both hours and minutes must occupy two spaces.
1330
The abbreviations used in the template descriptions are:
HH—The numerical hour based on a 24-hour clock. For example, 14 is 2 o’clock in the afternoon. For the 1 format, both spaces do not need to be occupied. However, the 2 format requires that both spaces be occupied. For example, 1:00 in the morning must be entered as 01.
MnThe number of minutes in the hour. For the 1 format, both spaces do not need to be occupied. However, the 2 format requires that both spaces be occupied. For example, 6 minutes must be entered as 06.
SS[.SSS]The number of seconds in the minute. A decimal part of a second is optional.
*Represents a delimiter that separates the different fields of data. The delimiter can also be a slash (/), a colon (:), a
hyphen (), or a comma (,).
 
note
You do not need both a date and time to use the STR_TO_DT function. You can enter a date only or a time only. For more information, refer to the STR_TO_DT function in the PV‑WAVE Reference.
Example 1
; The data contained in the strings corresponds to the date
; format MM DD YY and the time format HH Mn SS.
date2 = STR_TO_DT('3-13-92', '14:12:22',Date_Fmt = 1, $
Time_Fmt = -1)
DT_PRINT, date2
; PV-WAVE prints: 03/13/1992 14:12:22
Example 2
; You can convert a date without a time.
date3 = STR_TO_DT('4-12-92', Date_Fmt = 1)
DT_PRINT, date3
; PV-WAVE prints: 04/12/92
VAR_TO_DT Function
If you have read date/time elements into numeric variables, you can use the VAR_TO_DT function to convert these variables into date/time variables. This function is useful for converting time stamp data that does not conform to a format used by the STR_TO_DT function.
This function has the form:
result = VAR_TO_DT(yyyy, mm, dd, hr, mn, ss) 
Example
This example illustrates how to convert a numeric date/time value into date/time data and verify that a date/time variable has been created using the PRINT procedure.
z = VAR_TO_DT(1992, 11, 22, 12, 30)
PRINT, z
; PV-WAVE prints: { 1992 11 22 12 30 0.00000 87728.521 0}
SEC_TO_DT Function
In some instances, scientific and engineering data has been collected at regular intervals over long periods of time from a specified start date. Some examples include sun spot activity or seismic data about an active volcano. The SEC_TO_DT function is designed to handle this type of data. It converts any number of seconds into date/time variables. These variables are calculated from a specified base time. The default base, September 14, 1752, is defined by the system variable !DT_Base. You can change the base time by using the keyword Base.
This function has the form:
result = SEC_TO_DT(num_of_seconds)
Example
The example shows how to convert 20 seconds to a date/time variable. The example uses a base start date of January 1, 1970.
date = SEC_TO_DT(20, Base = '1-1-70', Date_Fmt = 1)
PRINT, date
; PV-WAVE prints: { 1970 1 1 0 0 20.0000 79367.000 0}
JUL_TO_DT Function
This function converts a Julian number into a date/time variable. For more information on how to use this function with the table functions, refer to the examples in the section "Using Date/Time Data in Tables".
This function has the form:
result = JUL_TO_DT(julian_date) 
Example
; Converts the Julian day 87507 to a date/time variable.
dt = JUL_TO_DT(87507)
PRINT, dt
; PV-WAVE prints: { 1992 4 15 0 0 0.00000 87507.000 0}

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.