Date Function: DatePart()

DatePart():

This function is used to extract the part of the Date with return type is integer.

Syntax:
DatePart (DateType,Datetime)

It requires two parameters separated by a comma (,).

First parameter: Type of date data will be extracted
second parameter: Time stamp value

Example:

SELECT DATEPART(year, '2015-10-22 15:58:31.537');
SELECT DATEPART (TZoffset, '2015-10-22 15:58:31.537 +05:00');

DatePart
Type
Return Value
year
yyyyyy
2015
quarter
qqq
4
month
mm, m
10
dayofyear
dyy
295
day
ddd
22
week
wkww
43
weekday
dw
5
hour
hh
15
minute
mi, n
58
second
ss, s
31
millisecond
ms
537
microsecond
mcs
537000
nanosecond
ns
537000000
TZoffset
tz
300
ISO_WEEK
isowkisoww
43

See Also:
GetDate()
GetUTCDate()
DateFromParts()
TimeFromParts()
DateDiff()

Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment