SQL Server CURRENT_DATE: How to Get Today's Date
In this article
SQL Server does not have a built-in CURRENT_DATE function like some other database systems (for example, MySQL or PostgreSQL). Instead, you use GETDATE() or SYSDATETIME() to get the current date and time, and then cast or convert the result to a date-only value. The simplest working approach is SELECT CAST(GETDATE() AS date); which returns today's date without the time component. This guide explains how to get the current date in SQL Server, how to use it in queries, and how to avoid common pitfalls.
What You'll Need
- Access to a SQL Server instance (any recent version, including Express, Standard, or Enterprise).
- A SQL client such as SQL Server Management Studio (SSMS), Azure Data Studio, or
sqlcmd. - Permission to run
SELECTstatements in the database you are using.
Step-by-Step
- Open your SQL client and connect to the database. In SSMS, enter the server name, choose authentication, and click Connect. In Azure Data Studio, create a new connection with the same details. If you are using
sqlcmd, runsqlcmd -S server_name -U username -P passwordand thenUSE your_database;. - Run a simple query to get the current date and time. Execute
SELECT GETDATE();This returns adatetimevalue that includes both date and time, based on the server's local time zone. For higher precision, useSELECT SYSDATETIME();which returns adatetime2value. - Convert the result to a date-only value. Use
CASTorCONVERTto strip the time portion:SELECT CAST(GETDATE() AS date);orSELECT CONVERT(date, GETDATE());Both return adatedata type with no time component. - Use the current date in a WHERE clause. For example, to find orders placed today:
SELECT * FROM Orders WHERE OrderDate = CAST(GETDATE() AS date);Note that ifOrderDateincludes a time, this exact match may miss rows; see Common Mistakes below. - Get the current date in a specific format. If you need a string like 'YYYY-MM-DD', use
SELECT CONVERT(varchar(10), GETDATE(), 23);Style 23 gives ISO format. For other formats, refer to theCONVERTstyle chart in SQL Server documentation. - Use
CURRENT_TIMESTAMPas an ANSI-compliant alternative.SELECT CURRENT_TIMESTAMP;is equivalent toGETDATE()and returns adatetimevalue. It is not a date-only function, but it is standard SQL and works in SQL Server. - Consider time zone differences.
GETDATE()uses the server's local time. If you need UTC, useGETUTCDATE()orSYSUTCDATETIME(). For example,SELECT CAST(GETUTCDATE() AS date);returns the current UTC date. - Test your query with sample data. Run a
SELECTthat includes both the current date and a date column from your table to verify how they compare. Adjust your logic if time components are present.
Common Mistakes
- Assuming
CURRENT_DATEexists. SQL Server does not supportCURRENT_DATE; using it will raise an error. UseCAST(GETDATE() AS date)instead. - Comparing a date column with a datetime value. If your column stores time,
WHERE OrderDate = CAST(GETDATE() AS date)will only match rows at midnight. Use a range:WHERE OrderDate >= CAST(GETDATE() AS date) AND OrderDate < DATEADD(day, 1, CAST(GETDATE() AS date)). - Forgetting about time zones.
GETDATE()returns server local time, which may differ from your application's time zone. UseGETUTCDATE()orSYSDATETIMEOFFSET()if you need consistency across regions. - Using
GETDATE()in a function or computed column without considering determinism.GETDATE()is non-deterministic, so it cannot be used in indexed views or persisted computed columns. UseSYSDATETIME()only in contexts where non-determinism is allowed.
Tips
- Use
CAST(GETDATE() AS date)for a clean date-only value; it is readable and efficient. - For date arithmetic, use
DATEADDandDATEDIFFwith thedatetype to avoid time component issues. - If you frequently need the current date, consider creating a scalar function that returns
CAST(GETDATE() AS date)for consistency, but be aware of performance implications in large queries. - When formatting dates for display, use
FORMAT(GETDATE(), 'yyyy-MM-dd')(SQL Server 2012+) for clarity, but note thatFORMATcan be slower thanCONVERT.
Troubleshooting
- Error: 'CURRENT_DATE' is not a recognized built-in function name. This confirms SQL Server does not have
CURRENT_DATE. Replace it withCAST(GETDATE() AS date). - Query returns no rows when filtering by today's date. Check if the column includes a time component. Use a range condition as shown in Common Mistakes.
- Date is off by one day. Verify the server's time zone and whether you need UTC. Use
GETUTCDATE()or adjust withSWITCHOFFSET. - Permission denied. Ensure your login has
SELECTpermission on the table or database.
Frequently Asked Questions
Is there a CURRENT_DATE function in SQL Server?
No, SQL Server does not have a CURRENT_DATE function. Use CAST(GETDATE() AS date) or CONVERT(date, GETDATE()) to get the current date.
What is the difference between GETDATE() and SYSDATETIME()?
GETDATE() returns a datetime value with millisecond precision (though accuracy is about 3.33 ms). SYSDATETIME() returns a datetime2 value with higher precision (100 ns). Both use the server's local time.
How do I get the current date in UTC?
Use CAST(GETUTCDATE() AS date) or CAST(SYSUTCDATETIME() AS date) to get the current UTC date without time.
Can I use CURRENT_TIMESTAMP to get the date?
CURRENT_TIMESTAMP returns a datetime value including time. To get only the date, cast it: CAST(CURRENT_TIMESTAMP AS date).
Why does my query return no results when I filter by today's date?
If the column you are filtering includes a time component, an exact match with a date-only value will fail. Use a range: WHERE column >= CAST(GETDATE() AS date) AND column < DATEADD(day, 1, CAST(GETDATE() AS date)).
How do I format the current date as a string?
Use CONVERT(varchar(10), GETDATE(), 23) for ISO format (yyyy-mm-dd), or FORMAT(GETDATE(), 'yyyy-MM-dd') for a customizable string (SQL Server 2012+).