Differences between revisions 1 and 2
Revision 1 as of 2022-08-11 16:31:50
Size: 1547
Comment:
Revision 2 as of 2022-08-11 16:47:51
Size: 1819
Comment:
Deletions are marked like this. Additions are marked like this.
Line 13: Line 13:
== Xdate == == Date ==
Line 15: Line 15:
The '''`XDATE`''' function extracts a component of a date or time value. The '''`DATE`''' function returns a date value.
Line 17: Line 17:
||'''Function''' ||'''Returns''' ||
||`xdate.year` ||Year ||
||`xdate.month` ||Month (1 to 12) ||
||`xdate.mday` ||Day of the month (1 to 31) ||
||`xdate.wkday` ||Day of the week (1 to 7) ||
||`xdate.jday` ||Day of the year (1 to 366) ||
||`xdate.hour` ||Hours ||
||`xdate.minute` ||Minutes ||
||`xdate.second` ||Seconds ||
{{{
compute jan_2_3000 = date.mdy(1, 2, 3000)
}}}
Line 28: Line 22:
Line 52: Line 47:
----
Line 64: Line 61:
----



== Time ==

The '''`TIME`''' function returns a time value.

{{{
compute two_thirty = time.hms(2, 30, 0)
}}}

----



== Xdate ==

The '''`XDATE`''' function extracts a component of a date or time value.

||'''Function''' ||'''Returns''' ||
||`xdate.year` ||Year ||
||`xdate.month` ||Month (1 to 12) ||
||`xdate.mday` ||Day of the month (1 to 31) ||
||`xdate.wkday` ||Day of the week (1 to 7) ||
||`xdate.jday` ||Day of the year (1 to 366) ||
||`xdate.hour` ||Hours ||
||`xdate.minute` ||Minutes ||
||`xdate.second` ||Seconds ||

SPSS Date Time Functions

While dates and times are simply a formatted numeric data type in SPSS, a set of built-in functions are offered for these variables.

To clarify, these functions operate at case level. They do not perform higher-level computations.


Date

The DATE function returns a date value.

compute jan_2_3000 = date.mdy(1, 2, 3000)


Datediff

The DATEDIFF function subtracts a date or time from another, returning an integer in terms of the specified unit.

num_days = datediff(date1,date2,"days")

Valid units include:

  • "years"

  • "quarters"

  • "months"

  • "weeks"

  • "days"

  • "hours"

  • "minutes"

  • "seconds"

Note that the returned value is floored using the specified unit.


Datesum

The DATESUM function adds some number of units to a date or time, returning a new date or time.

month_ago = datesum(date1,-1,"months")

Reference the above list for valid values of the third argument.


Time

The TIME function returns a time value.

compute two_thirty = time.hms(2, 30, 0)


Xdate

The XDATE function extracts a component of a date or time value.

Function

Returns

xdate.year

Year

xdate.month

Month (1 to 12)

xdate.mday

Day of the month (1 to 31)

xdate.wkday

Day of the week (1 to 7)

xdate.jday

Day of the year (1 to 366)

xdate.hour

Hours

xdate.minute

Minutes

xdate.second

Seconds


CategoryRicottone

SPSS/DatetimeFunctions (last edited 2023-11-30 19:42:09 by DominicRicottone)