By Ruben Geert van den Berg on May 29, 2013 under 4.4. SPSS Date Variables Tutorial.

# 4.4.1. SPSS Date Variables Basics

## Introduction

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 Type | Format family | Format (example) | Shown as |
---|---|---|---|

Numeric | Date | Date11 | 19-jan-2013 |

Numeric | Edate (= European date) | Edate10 | 19.01.2013 |

Numeric | Adate (= American date) | Adate10 | 01/19/2013 |

Numeric | Sdate (= Sortable date) | Sdate10 | 2013/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.