DATEPART (SSIS Expression)

 

Applies To: SQL Server 2016

Returns an integer representing a datepart of a date.

  
DATEPART(datepart, date)  

datepart
Is the parameter that specifies for which part of the date to return a new value.

date
Is an expression that returns a valid date or a string in date format.

DT_I4

DATEPART returns a null result if the argument is null.

A date literal must be explicitly cast to one of the date data types. For more information, see Integration Services Data Types.

The following table lists the dateparts and abbreviations recognized by the expression evaluator. Datepart names are not case sensitive.

DatepartAbbreviations
Yearyy, yyyy
Quarterqq, q
Monthmm, m
Dayofyeardy, y
Daydd, d
Weekwk, ww
Weekdaydw
HourHh
Minutemi, n
Secondss, s
MillisecondMs

This example returns the integer that represents the month in a date literal. If the date is in mm/dd/yyyy" format, this example returns 11.

DATEPART("month", (DT_DBTIMESTAMP)"11/04/2002")  

This example returns the integer that represents the day in the ModifiedDate column.

DATEPART("dd", ModifiedDate)  

This example returns the integer that represents the year of the current date.

DATEPART("yy",GETDATE())  

DATEADD (SSIS Expression)
DATEDIFF (SSIS Expression)
DAY (SSIS Expression)
MONTH (SSIS Expression)
YEAR (SSIS Expression)
Functions (SSIS Expression)

Community Additions

ADD
Show: