How to Extract a Component From a Datetime

A datetime in MS-SQL Server has different components like day, month, hour or minute among others. If you need to extract one of them.

select 	getdate() 				        original_value,
		datepart(hour, getdate()) 	    hour,
		datepart(minute, getdate()) 	minute,
		datepart(day, getdate()) 	    day,
		datepart(month, getdate()) 	    month
original_value hour minute day month
2021-11-24 08:20:21.713 8 20 24 11

IN THIS PAGE