BaşlayınÜcretsiz Başlayın

Break a date and time into component parts

Although YEAR(), MONTH(), and DAY() are helpful functions and are easy to remember, we often want to break out dates into different component parts such as the day of week, week of year, and second after the minute. This is where other functions we have learned come into play.

Here we will use the night the Berlin Wall fell, November 9th, 1989.

Bu egzersiz

Time Series Analysis in SQL Server

kursunun bir parçasıdır
Kursu Görüntüle

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

DECLARE
	@BerlinWallFalls DATETIME2(7) = '1989-11-09 23:49:36.2294852';

-- Fill in each date part
SELECT
	DATEPART(____, @BerlinWallFalls) AS TheYear,
	DATEPART(____, @BerlinWallFalls) AS TheDayOfYear,
	DATEPART(____, @BerlinWallFalls) AS TheDay,
	DATEPART(____, @BerlinWallFalls) AS TheWeek,
	DATEPART(____, @BerlinWallFalls) AS TheSecond,
	DATEPART(____, @BerlinWallFalls) AS TheNanosecond;
Kodu Düzenle ve Çalıştır