Use Of DATEPART() Function In Sql Server
Join the DZone community and get the full member experience.Join For Free
The DATEPART() function is used to return a single part of a date/time, such as year, month, day, hour, minute, etc. Syntax DATEPART(datepart,date) The following SELECT statement:
SELECT DATEPART(yyyy,OrderDate) AS OrderYear, DATEPART(mm,OrderDate) AS OrderMonth, DATEPART(dd,OrderDate) AS OrderDay, FROM Orders WHERE OrderId=1OUTPUT OrderYear OrderMonth OrderDay 2008 11 11 Spring Framework
Opinions expressed by DZone contributors are their own.