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;
Year | Month | Day | Dayofyear | Week | Weekday | Quarter |
---|---|---|---|---|---|---|
2014 | 2 | 22 | 53 | 8 | 7 | 1 |
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;
Hour | Minute | Second | Millisecond | Microsecond | Nanosecond |
---|---|---|---|---|---|
8 | 23 | 49 | 123 | 123456 | 123456700 |