In SPSS, a date variable is a variable holding the number of seconds since (roughly) the year 1582. It is this format which makes it possible to do date calculations such as adding days to a date.
SPSS Date Variables
- In SPSS, a date variable is just a number like any other number such as annual income or number of children in a household.
- However, date variables usually hold very large numbers since their actual values are the numbers of seconds since the Gregorian calender started (October 14th, 1582).
- The reason for this format is that it renders time calculations as simple as adding and subtracting (large) numbers.
- However, these large numbers are not easy to read by most people. Therefore, the dates represented by them can be shown instead of the actual values in numbers of seconds.
- This is done by the
FORMATScommand. Note that this does not change the underlying number of seconds. It's only displayed differently.
SPSS Date Formats
There are various ways to display dates in SPSS. A date format can be set by (e.g.)
FORMATS birthday (EDATE10). Again, note that this does not change the underlying value in seconds. The most common date formats are
- 31-DEC-99 (dd-mmm-yy) is referred to as DATE9; months are shown as three letter abbreviations and the
9refers to the number of characters used by this notation.
- 31-DEC-1999 (dd-mmm-yyyy) is referred to as DATE11.
- 31.12.99 (dd.mm.yy) is referred to as EDATE8 (European date).
- 31.12.1999 (dd.mm.yyyy) is referred to as EDATE10.
- 12/31/99 (mm/dd/yy) is referred to as ADATE8 (American date).
- 12/31/1999 (mm/dd/yyyy) is referred to as ADATE10.
- 99/12/31 (yy/mm/dd) is referred to as SDATE8 (Sortable date). It is sortable because its alphabetical order corresponds to its chronological order. This does not hold for the aforementioned formats.
- 1999/12/31 (yyyy/mm/dd) is referred to as SDATE10.
SPSS Date Functions
- For the number of days (or other time units) between two dates, use the
DATEDIFFfunction. For an example, see Compute Age.
- For extracting a year (or other time unit) from a date, use the
XDATEfunction. For an example, see Extract a Year from a Date.
- For finding what date it will be in 90 days (or other time unit), use the
DATESUMfunction. For an example, see Convert Unix Dates into SPSS Dates.
- For creating an SPSS date value (number of seconds) given a day, month and year, use the
DATE.DMYfunction. For an example, see Convert Numeric to Date Variable.
SPSS Date Format Demonstration
- This tutorial was written in 2012. So since 1582, 430 years have gone by.
- A year roughly holds 365.25 days, so that gives us some 16,000 days. This comes down to some 3.8 million hours.
- Multiplying by 3600 (the number of seconds per hour) implies that some 13.6 billion seconds have passed between 1582 and 2012.
- This value may be written as
1.36E10in SPSS. So entering this value should result in a date close to 2012 after displaying it as a date. Running the syntax below confirms that this is the case.
SPSS Date Syntax Example