Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Use Of DATEPART() Function In Sql Server

DZone's Guide to

Use Of DATEPART() Function In Sql Server

·
Free Resource
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=1 


OUTPUT
OrderYear	OrderMonth	OrderDay
2008	        11	        11

Spring Framework
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}