SPSS TUTORIALS FULL COURSE BASICS ANOVA REGRESSION FACTOR

# SPSS Date Variables Basics

SPSS date variables may seem a bit puzzling at first. However, getting things done fast and accurately with SPSS date variables is not hard at all if you understand some basics. This tutorial will walk you through. You can follow along by downloading and opening hospital.sav.

## SPSS Date Variables - What Are They?

First of all, SPSS date variables are numeric variables; their actual values are just numbers. More precisely, the numbers they hold are the number of seconds between the year 1582 and the start (midnight) of a given date. Realizing that it's these underlying values that date calculations act upon renders SPSS date logic straightforward.
Second, these huge numbers are usually shown as normal dates by setting their format to one of SPSS' main date formats. We'll outline some of those in the table below.

## SPSS Date Formats

As we just mentioned, SPSS date values are always numbers of seconds. You can choose several formats for displaying them as actual dates. Some main options are given in the table below.

Variable TypeFormat familyFormat (example)Shown as
NumericDateDate1119-jan-2013
NumericEdate (= European date)Edate1019.01.2013
NumericSdate (= Sortable date)Sdate102013/01/19

As suggested by this table, we recommend that you always display years as 4 digits instead of 2.A reason for this is explained in Two Digit Year in String - Cautionary Note.

## SPSS Date Variables - Example

The aforementioned points may sound rather abstract so let's demonstrate them on our data. It contains one proper date variable, entry_date. We'll take a look at its actual values by giving it an an f format. Running the following line of syntax does just that. formats entry_date(f1).

The date values now look very differently in data view. However, they are still the exact same values that we had a few seconds ago; they're just displayed differently. We'll now show them as dates by running formats entry_date(sdate10). After doing so, the actual date values look like date values again. Again, keep in mind that actual values still haven't changed in any way.

## SPSS Date Calculations

So why bother about the huge numbers that underlie SPSS date values? The reason is that its these values that SPSS date functions act upon.
When we understand that date values are really numbers of seconds, it becomes very easy to add, say, one day to date values. Note that one day is 60 (seconds) * 60 (minutes) * 24 (hours) = 86400 seconds. Now watch what happens when we simply add 86400 to our date variable by running the syntax below.

*Add one day (= 86400 seconds) to date variable.

compute entry_date = entry_date + 86400.
exe.

Indeed, exactly one day has been added to all values. However, adding a month is more complicated because different months hold different numbers of days.
For such cases SPSS has some specialized date functions that render such operations a piece of cake. The next tutorial will walk you through the most important ones.

# Tell us what you think!

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

# THIS TUTORIAL HAS 8 COMMENTS:

• ### By Ruben Geert van den Berg on October 24th, 2019

Hi Teodora!

First off, we strongly recommend you work from syntax. Changing string variables into dates can usually be done with the ALTER TYPE command. This requires you specify the correct date format as in

`ALTER TYPE mystring (EDATE11).`

where EDATE11 means your string values must look like 27-10-2019 (dd-mm-yyyy).

If that's too challenging, you can send us (some records of) your .xlsx file by email and we'll fix it for you.

Hi,