Skip to content

Using The TSQL DATEPART Function

Here is a quick video training on how to use the T-SQL DATEPART function on SQL Server. This was originally part of my free SQL query training for the 70-461 certification exam.

And here is the sample code to go with the video tutorial:

 SELECT DATEPART(year, GETDATE()) AS [year],
		DATEPART(quarter, GETDATE()) AS [quarter],
		DATEPART(month, GETDATE()) AS [month],
		DATEPART(dayofyear, GETDATE()) AS [dayofyear],
		DATEPART(day, GETDATE()) AS [day],
		DATEPART(week, GETDATE()) AS [week],
		DATEPART(weekday, GETDATE()) AS [weekday],
		DATEPART(hour, GETDATE()) AS [hour],
		DATEPART(minute, GETDATE()) AS [minute],
		DATEPART(second, GETDATE()) AS [second],
		DATEPART(millisecond, GETDATE()) AS [millisecond],
		DATEPART(microsecond, GETDATE()) AS [microsecond],
		DATEPART(nanosecond, GETDATE()) AS [nanosecond],
		DATEPART(ISO_WEEK, GETDATE()) AS [ISO_WEEK];

See Also


More from Stedman Solutions:

SteveStedman5
Steve and the team at Stedman Solutions are here for all your SQL Server needs.
Contact us today for your free 30 minute consultation..
We are ready to help!

Leave a Reply

Your email address will not be published. Required fields are marked *