T-SQL Tutorial

DATEPART Date Function


Datepart is an date function and returns an integer that represents the specified datepart(year, month or day) of the specified date.

DATEPART Syntax:

DATEPART (datepart, date)

DATEPART Example:

SELECT DATEPART(year,'2014-02-22 08:23:49.1234567 +05:10') as Year,
DATEPART(month,'2014-02-22 08:23:49.1234567 +05:10') as Month,
DATEPART(day,'2014-02-22 08:23:49.1234567 +05:10') as Day,
DATEPART(dayofyear,'2014-02-22 08:23:49.1234567 +05:10') as Dayofyear,
DATEPART(week,'2014-02-22 08:23:49.1234567 +05:10') as Week,
DATEPART(weekday,'2014-02-22 08:23:49.1234567 +05:10') as Weekday,
DATEPART(quarter,'2014-02-22 08:23:49.1234567 +05:10') as Quarter;

YearMonthDayDayofyearWeekWeekdayQuarter
201422253871

SELECT DATEPART(hour,'2014-02-22 08:23:49.1234567 +05:10') as Hour,
DATEPART(minute,'2014-02-22 08:23:49.1234567 +05:10') as Minute,
DATEPART(second,'2014-02-22 08:23:49.1234567 +05:10') as Second,
DATEPART(millisecond,'2014-02-22 08:23:49.1234567 +05:10') as Millisecond,
DATEPART(microsecond,'2014-02-22 08:23:49.1234567 +05:10') as Microsecond,
DATEPART(nanosecond,'2014-02-22 08:23:49.1234567 +05:10') as Nanosecond;

HourMinuteSecondMillisecondMicrosecondNanosecond
82349123123456123456700