PV-WAVE Foundation > User Guide > Working with Date/Time Data > Writing Date/Time Data to a File
Writing Date/Time Data to a File
There are two methods for writing date/time data to a file. You can use DC_WRITE functions to both convert and write data or you can first convert the date/time data and then write it to a file.
Using DC_WRITE Functions
You can use DC_WRITE functions to convert data from the date/time format to another format and then write the new date/time data to a file. The DC_WRITE functions are easy to use because they automatically handle many aspects of data transfer, such as opening and closing the data file.
The two DC_WRITE functions that you can use to convert and write data are DC_WRITE_FIXED and DC_WRITE_FREE. For examples and a detailed discussion of these two functions, refer to their descriptions in the PV‑WAVE Reference.
 
note
By default, DC_WRITE_FREE generates CSV (Comma Separated Value) ASCII data files.
Using Conversion Routines
You can also use three conversion routines in conjunction with the WRITE and WRITEU procedures to convert date/time data for output to a file. The conversion routines are:
*DT_TO_SEC
*DT_TO_STR
*DT_TO_VAR
DT_TO_STR Procedure
This procedure converts date/time variables to strings. The procedure has the form:
DT_TO_STR, dt_var 
Example
Assume you have a date/time variable named date1 that contains the following date/time structures:
{ 1992 3 13 1 10 34.0000 87474.049 0}
{ 1983 4 20 16 18 30.0000 84224.680 0}
{ 1964 4 24 5 7 25.0000 77289.213 0}
To convert to data, use the DT_TO_STR procedure:
; Convert date/time data. Stores the date data in d and the
; time data in t. The Date_Fmt and Time_Fmt  keywords define
; the formats that date1 is using. DT_TO_STR uses the same
; formats as STR_TO_DT. 
; See "STR_TO_DT Function" for an 
; explanation of valid formats.
DT_TO_STR, date1, d, t, Date_Fmt=1, Time_Fmt=-1
PRINT, d
; PV-WAVE prints: 03/13/1992 04/20/1983 04/24/1964
PRINT, t
; PV-WAVE prints: 01:10:34 16:18:30 05:07:25
DT_TO_VAR Procedure
This procedure converts date/time variables into variables that contain numerical date/time information. The procedure has the form:
DT_TO_VAR, dt_value 
Example
Assume that you have created a date/time variable named date1 that contains the following date/time data:
{ 1992 3 13 10 34 15.0000 87474.440 0}
{ 1983 4 20 12 30 19.0000 84224.521 0}
{ 1964 6 24 16 25 14.0000 77350.684 0}
To convert the data in this date/time variable:
; This procedure creates several variables containing the 
; date/time data.
DT_TO_VAR, date1, Year = years, Month = months, Day = days
; The keyword Year generates an integer array that contains
; the years.
PRINT, 'Years =', years
; PV-WAVE prints: Years = 1992 1983 1964
 
; The keyword Month creates a byte array with the months.
PRINT, 'Months =', months
; PV-WAVE prints: Months = 3 4 6
 
; The keyword Day creates a byte array with the days of the month.
PRINT, 'Days =', days
; PV-WAVE prints: Days = 13 20 24
DT_TO_SEC Function
This function converts date/time data into seconds. The function has the form:
result = DT_TO_SEC(dt_value) 
Example
Assume that you have created the array dtarray that contains the following date/time data:
{ 1992 4 15 7 29 19.0000 87507.312 0}
{ 1993 4 15 7 29 19.0000 87872.312 0}
{ 1994 4 15 7 29 19.0000 88237.312 0}
To find out the number of seconds for each date/time from January 1, 1970, use the DT_TO_SEC function:
seconds = DT_TO_SEC(dtarray, Base = '1-1-70', Date_Fmt = 1)
PRINT, seconds
; PV-WAVE prints: 7.0332296e+08 7.3485896e+08 7.6639496e+08