Date and time conversion functions
The conversion functions convert time intervals from one unit of time to another. Time intervals are stored as the number of seconds in the interval; the conversion functions provide a means for calculating more appropriate units, for example, converting seconds to days.
Each conversion function consists of the CTIME function followed by a period (.), the target time unit, and an argument. The argument can consist of expressions, variable names, or constants. The argument must already be a time interval. See the topic Aggregation functions for more information. Time conversions produce noninteger results with a default format of F8.2.
Since time and dates are stored internally as seconds, a function that converts to seconds is not necessary.
CTIME.DAYS. CTIME.DAYS(timevalue). Numeric. Returns the number of days, including fractional days, in timevalue, which is a number of seconds, a time expression, or a time format variable.
CTIME.HOURS. CTIME.HOURS(timevalue). Numeric. Returns the number of hours, including fractional hours, in timevalue, which is a number of seconds, a time expression, or a time format variable.
CTIME.MINUTES. CTIME.MINUTES(timevalue). Numeric. Returns the number of minutes, including fractional minutes, in timevalue, which is a number of seconds, a time expression, or a time format variable.
CTIME.SECONDS. CTIME.SECONDS(timevalue). Numeric. Returns the number of seconds, including fractional seconds, in timevalue, which is a number, a time expression, or a time format variable.
Example
DATA LIST FREE (",")
/StartDate (ADATE12) EndDate (ADATE12)
StartDateTime(DATETIME20) EndDateTime(DATETIME20)
StartTime (TIME10) EndTime (TIME10).
BEGIN DATA
3/01/2003, 4/10/2003
01-MAR-2003 12:00, 02-MAR-2003 12:00
09:30, 10:15
END DATA.
COMPUTE days = CTIME.DAYS(EndDate-StartDate).
COMPUTE hours = CTIME.HOURS(EndDateTime-StartDateTime).
COMPUTE minutes = CTIME.MINUTES(EndTime-StartTime).
- CTIME.DAYS calculates the difference between EndDate and StartDate in days—in this example, 40 days.
- CTIME.HOURS calculates the difference between EndDateTime and StartDateTime in hours—in this example, 24 hours.
- CTIME.MINUTES calculates the difference between EndTime and StartTime in minutes—in this example, 45 minutes.