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
- Additional Training on my YouTube Channel
- Free SQL Query Training
- 70-461 exam preparation
More from Stedman Solutions:
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!