Calculating the Length of Time between Two Dates

One of the most common tasks involving dates is calculating the length of time between two dates. As an example, consider a software company interested in analyzing purchases of upgrade licenses by determining the number of years since each customer last purchased an upgrade. The data file upgrade.sav contains a variable for the date on which each customer last purchased an upgrade but not the number of years since that purchase. A new variable that is the length of time in years between the date of the last upgrade and the date of the next product release will provide a measure of this quantity.

To calculate the length of time between two dates:

  1. Select Calculate with dates and times on the introduction screen of the Date and Time Wizard and click Next.
  2. Select Calculate the number of time units between two dates and click Next.
    Figure 1. Calculating the length of time between two dates: Step 2
    Calculating the length of time between two dates: Step 2
  3. In step 2, select Date of next release for Date1.
  4. Select Date of last upgrade for Date2.
  5. Select Years for the Unit and Truncate to Integer for the Result Treatment. (These are the default selections.)
  6. Click Next.
  7. In step 3, enter YearsLastUp for the name of the result variable. Result variables cannot have the same name as an existing variable.
  8. Enter Years since last upgrade as the label for the result variable. Variable labels for result variables are optional.
  9. Leave the default selection of Create the variable now, and click Finish to create the new variable.

The new variable, YearsLastUp, displayed in the Data Editor is the integer number of years between the two dates. Fractional parts of a year have been truncated.

Next