Extract parts of dates - using DATENAME, DATEPART, DAY, MONTH and YEAR functions in SQL Server

preview_player
Показать описание
In this video, we will be retrieving only part of a date or time from a datetime.
My SQL Server Udemy courses are:
----
My Excel for PC courses are:
----
If you want to retrieve the Day, Month or Year from a date field, then you can use the DAY, MONTH and YEAR functions. However, there isn't an HOUR function.
Instead, you can use the DATENAME and DATEPART functions to do the same thing. DATENAME retrieves a string, such as 'April', whereas DATEPART retrieves an int, such as 4. Using these functions, you can then get any element of a date.
However, there are some quirks that you should know, especially when you are getting the WEEK from a date. You can specify which is the first day of a week by using SET DATEFIRST.
Рекомендации по теме
Комментарии
Автор

I love your teaching so much, how detailed and exciting your voice sings is so great. Please do well to add Microsoft excel.

allisonjoyalali
Автор

I tried datepart function but it said that datepart function doesn't exist.

bucagmarklesterg.