SPSS Tutorials

BASICS REGRESSION T-TEST ANOVA CORRELATION

Extract a Year from a Date

Introduction

Extracting the year (or any component) from a date is straightforward with the XDATE ("EXtract DATE") function. Copy-paste-run the syntax presented below for a demonstration of XDATE.

SPSS Xdate Syntax Example

*1. Create mini test data.

data list free/date(edate10).
begin data
'01/01/01'
'12/12/12'
end data.

*2. Extract the year.

compute year_from_date = xdate.year(date).
exe.

*3. Hide decimals for year_from_date.

format year_from_date(f4.0).

Notes

Previous tutorial: Convert Unix Dates into SPSS Dates

Next tutorial: SPSS – Convert String into Date Variable

Let me know what you think!

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

This tutorial has 3 comments