DATEPART (SSIS)

Returns an integer representing a datepart of a date.

Syntax

DATEPART(datepart, date)

Arguments

  • 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.

Result Types

DT_I4

Remarks

DATEPART returns a null result if the argument is null.

A date literal must be explicitly cast to one of the date data types.

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

Datepart Abbreviations

Year

yy, yyyy

Quarter

qq, q

Month

mm, m

Dayofyear

dy, y

Day

dd, d

Week

wk, ww

Weekday

dw, w

Hour

Hh

Minute

mi, n

Second

ss, s

Millisecond

Ms

Examples

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())

See Also

Reference

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

Other Resources

Functions (SSIS)

Help and Information

Getting SQL Server 2005 Assistance

Change History

Release History

5 December 2005

New content:
  • Added table of dateparts and abbreviations that you can use with the DATEPART function.