LoslegenKostenlos loslegen

Break out a date into year, month, and day

SQL Server has a number of functions dedicated to working with date types. We will first analyze three functions which return integers representing the year, month, and day of month, respectively.

These functions can allow us to group dates together, letting us calculate running totals by year or month-over-month comparisons of expenditures. We could also analyze sales by calendar day of the month to determine if there is a strong monthly cycle.

Diese Übung ist Teil des Kurses

Time Series Analysis in SQL Server

Kurs anzeigen

Anleitung zur Übung

  • Use the YEAR(), MONTH(), and DAY() functions to determine the year, month, and day for the current date and time.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

DECLARE
	@SomeTime DATETIME2(7) = SYSUTCDATETIME();

-- Retrieve the year, month, and day
SELECT
	___(@SomeTime) AS TheYear,
	___(@SomeTime) AS TheMonth,
	___(@SomeTime) AS TheDay;
Code bearbeiten und ausführen