Using The TSQL DATEPART Function

Download PDF

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

Tagged with: , ,

Leave a Reply

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

*

Time limit is exhausted. Please reload CAPTCHA.