SPSS tutorials website header logo SPSS TUTORIALS BASICS ANOVA REGRESSION FACTOR 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

Tell us what you think!

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

THIS TUTORIAL HAS 3 COMMENTS: