SPSS tutorials website header logo SPSS TUTORIALS BASICS ANOVA REGRESSION FACTOR CORRELATION

Convert Numeric to Date Variable

For time calculations (such as the number of days between two dates) proper date variables are needed. In some cases, the digits of a numeric variable may represent year, month and day. This tutorial shows how to convert this format into an actual date variable.

Convert Numbers to SPSS Date Variables

In some cases, dates are represented as numeric variables whose digits represent a year, month and day (often referred to as YYYY-MM-DD). This format is not suitable for any time based calculations which require an actual date variables. The solution for this is to convert the original variable into an actual date variable. This is demonstrated by the syntax below.

SPSS Date Function Syntax Example

*1. Create test data.

data list free/date(f8).
begin data
20111030
end data.

*2. Convert into date format.

compute realdate = date.dmy(mod(date,10**2),tru(mod(date,10**4)/10**2),tru(date/10**4)).
format realdate(edate10).
exe.

SPSS Date Function Explanation

Tell us what you think!

*Required field. Your comment will show up after approval from a moderator.