SQL DATEPART Function


  SQL > SQL Date Functions > Datepart Function

DATEPART is a SQL Server function that extracts a specific part of the date/time value. Its syntax is as follows:

DATEPART (part_of_day, expression)

where part_of_day can have the following:

datepartabbreviation
yearyy, yyyy
quarterqq, q
monthmm, m
dayofyeardy, y
daydd, d
weekwk, ww
hourhh
minutemi, n
secondss, s
millisecondms
microsecondmcs
nanosecondns
TZoffsettz
ISO_WEEKisowk, isoww

Example 1:

SELECT DATEPART (yyyy,'2000-01-20');

Result:

2001

Example 2:

SELECT DATEPART(dy, '2000-02-10');

Result:

41

2000-02-01 is the 41st day in the year 2000.

SQL GETDATE >>

Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.



More 1Keydata Tutorials



Copyright © 2012   All Rights Reserved.         Privacy Policy  



SQL DATEADD
SQL DATEDIFF
SQL DATEPART
SQL GETDATE
SQL SYSDATE

SQL Jobs

Site Map
Resources