SPSS Date Time Functions
While dates and times are simply a formatted numeric data type in SPSS, a set of built-in functions are offered for these variables.
To clarify, these functions operate at case level. They do not perform higher-level computations.
Date
The DATE function returns a date value.
compute jan_2_3000 = date.mdy(1, 2, 3000)
Datediff
The DATEDIFF function subtracts a date or time from another, returning an integer in terms of the specified unit.
num_days = datediff(date1,date2,"days")
Valid units include:
"years"
"quarters"
"months"
"weeks"
"days"
"hours"
"minutes"
"seconds"
Note that the returned value is floored using the specified unit.
Datesum
The DATESUM function adds some number of units to a date or time, returning a new date or time.
month_ago = datesum(date1,-1,"months")
Reference the above list for valid values of the third argument.
Time
The TIME function returns a time value.
compute two_thirty = time.hms(2, 30, 0)
Xdate
The XDATE function extracts a component of a date or time value.
Function |
Returns |
xdate.year |
Year |
xdate.month |
Month (1 to 12) |
xdate.mday |
Day of the month (1 to 31) |
xdate.wkday |
Day of the week (1 to 7) |
xdate.jday |
Day of the year (1 to 366) |
xdate.hour |
Hours |
xdate.minute |
Minutes |
xdate.second |
Seconds |