SQL Server Get Today’s Date

In this comprehensive article, I’ll explain the various approaches to getting today’s date in SQL Server and help you choose the correct function for your specific requirements.

SQL Server Get Today’s Date

Before diving into the specifics, it’s essential to understand that SQL Server provides multiple built-in functions for retrieving the current date and time.

Approach-1: Using GETDATE()

The most commonly used function to retrieve the current date and time in SQL Server is GETDATE(). This function returns the current database system date and time in the ‘YYYY-MM-DD hh:mm.mmm’ format.

SELECT GETDATE() AS CurrentDateTime

After executing the above query, I got today’s date with time as expected, as shown in the screenshot below.

SQL Server Get Today's Date

If you only need the date part without the time component, you can use the query below with the CAST function.

SELECT CAST(GETDATE() AS DATE) AS CurrentDate

After executing the above query, I got the output as expected as per the below screenshot.

sql server get today's date without time

Note that GETDATE() is available in all versions of SQL Server.

Approach-2 : Using SYSDATETIME()

If you need higher-precision timestamps, SYSDATETIME() is the preferred choice. This function returns the date and time with fractional-second precision up to 7 digits (100 nanoseconds).

SELECT SYSDATETIME() AS CurrentDateTime

After executing the above query, I got the expected output as shown in the screenshot below.

get today's date in sql server

To extract just the date, we can execute the following query.

SELECT CAST(SYSDATETIME() AS DATE) AS CurrentDate

After the above query execution, I got the output as expected, as per the below screenshot.

how to get today's date in sql server

Approach-3 : Using GETUTCDATE()

SQL Server provides UTC-specific date functions that return the current date and time in Coordinated Universal Time (UTC).

We can also use the GETUTCDATE() with the following query.

Select GETUTCDATE() as currentdatetime

I got the expected output after executing the above query. Check out the screenshot below.

sql server today's date without time

If you wish to get only the date part, then we can use the following query.

SELECT CAST(GETUTCDATE() AS DATE) AS CurrentDate

I got the expected output as shown in the screenshot below.

sql server today's date

Approach-4: Using SYSUTCDATETIME()

We can use the SYSUTCDATETIME() UTC-specific date functions for this purpose. Let’s execute the query below to get today’s date and time.

Select SYSUTCDATETIME() as Todaydatetime;

After executing the above query, I got the successful output as shown in the screenshot below.

ms sql server today's date

If you wish to retrieve only the date part, you can use the following query.

SELECT CAST(SYSUTCDATETIME() AS DATE) AS TodayDate

I got the expected output as per the screenshot below.

sql today's date

Comparison of Date Functions in SQL Server

Here’s a comparison of the most commonly used date functions:

FunctionReturn TypePrecisionTime Zone AwarenessSQL Standard
GETDATE()datetime3 millisecondsNoNo
CURRENT_DATEdateDayNoYes
SYSDATETIME()datetime2100 nanosecondsNoNo
GETUTCDATE()datetime3 millisecondsYes (UTC)No
SYSUTCDATETIME()datetime2100 nanosecondsYes (UTC)No

Practical Usage for Today’s Date inside SQL Server table

Filtering Records for Today

Here’s how to get all the records from today’s sales table.

SELECT * FROM sales 
WHERE CAST(sale_Date AS DATE) = CAST(GETDATE() AS DATE)

After executing the above query, I got the expected output as shown in the screenshot below.

sql today's date function

Similarly, you can execute the query below to get the date ranges.

SELECT * FROM sales 
WHERE sale_Date BETWEEN DATEADD(DAY, -30, CAST(GETDATE() AS DATE)) AND CAST(GETDATE() AS DATE)

After executing the above query, I got the expected output as shown in the screenshot below.

sql today's date no time

Creating Default Values

Today’s date is often used as the default value for date columns. Let’s create a table using the query below.

CREATE TABLE DefaultEmployees (
    EmployeeID INT PRIMARY KEY,
    Name NVARCHAR(100),
    Hire_Date DATE DEFAULT CAST(GETDATE() AS DATE)
)

After executing the above query, the table was created successfully with the default column value, as per the screenshot below.

microsoft sql today's date

Video Tutorial

Conclusion

Getting today’s date in SQL Server may seem straightforward, but as this article explains, there are multiple approaches with different advantages depending on your specific needs.

For most scenarios, GETDATE() combined with CAST is sufficient. If you require high precision or time zone information, consider SYSDATETIME() or the UTC variants.

You may also like the following articles.