- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Get the Hour From a SQL Server DateTime or Column Value
Here's a quick video to show you how to find the current hour or the hour value from a column value in SQL Server.
00:00 - Hour from current datetime
00:32 - Hour from column value
01:20 - Beware of empty time columns
Use the GETDATE() function to get the current date and time:
SELECT GETDATE() AS 'Date and Time'
Pass the DATEPART() function with the 'hour' and a GETDATE() parameter to return the current hour:
SELECT DATEPART(hour, GETDATE()) AS 'Hour'
You can also use DATEPART to return just the hour from a DATETIME column value:
SELECT TOP 10 Title, DateUpdated, DATEPART(hour, DateUpdated) AS 'HourUpdated', YouTubeKeywords FROM findachannel.t_creators
Just a quick warning that not all DateTime columns have the time part set. For example I don't think there are any times held within the DateTime columns in Microsoft's AdventureWorks SQL Server sample database.
If you found this video leave a LIKE and SUBSCRIBE for more coding videos.
Check out my SQL Programming playlist for more tutorials: https://www.youtube.com/playlist?list=PLVQbq9wVileaQK3hur907sqqJZwgmjpoT
Thumbnail photo credit: https://unsplash.com/@mpho_mojapelo
Видео Get the Hour From a SQL Server DateTime or Column Value канала Coding With Brett
00:00 - Hour from current datetime
00:32 - Hour from column value
01:20 - Beware of empty time columns
Use the GETDATE() function to get the current date and time:
SELECT GETDATE() AS 'Date and Time'
Pass the DATEPART() function with the 'hour' and a GETDATE() parameter to return the current hour:
SELECT DATEPART(hour, GETDATE()) AS 'Hour'
You can also use DATEPART to return just the hour from a DATETIME column value:
SELECT TOP 10 Title, DateUpdated, DATEPART(hour, DateUpdated) AS 'HourUpdated', YouTubeKeywords FROM findachannel.t_creators
Just a quick warning that not all DateTime columns have the time part set. For example I don't think there are any times held within the DateTime columns in Microsoft's AdventureWorks SQL Server sample database.
If you found this video leave a LIKE and SUBSCRIBE for more coding videos.
Check out my SQL Programming playlist for more tutorials: https://www.youtube.com/playlist?list=PLVQbq9wVileaQK3hur907sqqJZwgmjpoT
Thumbnail photo credit: https://unsplash.com/@mpho_mojapelo
Видео Get the Hour From a SQL Server DateTime or Column Value канала Coding With Brett
Комментарии отсутствуют
Информация о видео
28 февраля 2022 г. 13:53:20
00:01:42
Другие видео канала




















