DATEPART returns the numeric portion of a date.

Syntax

DATEPART ( dateType, date)

Arguments

  • dateType: The date type. The dateType can be one of the following: year, month, day, hour, minute, second, dayofyear, dayofweek, quarter, week. dateType is not case sensitive.
  • date: A value of type DATE, TIME, or TIMESTAMP.

Returns

  • An INTEGER of the numeric portion specified.

Examples

SELECT DATEPART(Year,'2013-07-23 23:59:59'), DATEPART(Month,'2013-07-23 23:59:59'),
      DATEPART(day, '2013-07-23 23:59:59'), DATEPART(hour, '2013-07-23 23:59:59'),
      DATEPART(minute,'2013-07-23 23:59:59'), DATEPART(second,'2013-07-23 23:59:59'),
      DATEPART(dayofyear, '2013-07-23 23:59:59'), DATEPART(dayofweek, '2013-07-23 23:59:59') ,
      DATEPART(week, '2013-07-23 23:59:59'), DATEPART(quarter, '2013-07-23 23:59:59')
FROM "redshift1.inventory.sampleData";

-- Returns
2013 7     23    23    59    59    204   3     30    3