Search⌘ K
AI Features

Date and Time Functions

Explore core T-SQL date and time functions used in Microsoft SQL Server to retrieve and manipulate datetime data. Understand how to extract specific parts such as year, month, day, and perform calculations like adding or subtracting time components. This lesson equips you to handle dates and times efficiently in your database queries.

All applications work with date and time at some point. Fortunately, we do not have to reinvent the wheel and write our own functions when working with date and time in MS SQL Server. T-SQL has a number of functions for this purpose.

Current date and time

We can check the current date and time by looking at the system clock. The GETDATE() function returns an object of type DATETIME, which will show the local date and time according to the system clock:

SELECT GETDATE()
Using the GETDATE() function to retrieve the current date and time

In the output, we see the current date and time of the system that hosts our MS SQL Server instance.

If an application needs to ...