How to Get the Current Date in SQL Server

Galaxy Glossary

How do I get the current date in SQL Server?

GETDATE() and CURRENT_TIMESTAMP return the server’s current date and time.

Sign up for the latest in SQL knowledge from the Galaxy Team!

Description

What is the quickest way to fetch todays date in SQL Server?

Use GETDATE() or CURRENT_TIMESTAMP. Both return the current date-time from the SQL Server instance, including milliseconds, in the datetime data type.

How do I extract only the date part?

Wrap the function with CAST( … AS date) or use CONVERT(date, …) to strip the time component.

Can I get the date in a specific format?

Apply FORMAT() or CONVERT(varchar, …, style). For example, FORMAT(GETDATE(),'yyyy-MM-dd') returns an ISO-8601 date string.

Example: creating todays orders report

The query filters todays rows in the Orders table by comparing order_date to CAST(GETDATE() AS date). This ensures time is ignored.

Best practice tips

Store dates in UTC when possible, keep calculations in SQL to avoid client-side drift, and prefer SYSUTCDATETIME() if you need microsecond precision in UTC.

What are common mistakes to avoid?

Avoid comparing a datetime column directly to GETDATE() when you intend a date-only match; always cast both sides to date. Also, dont format the date for comparison—formatting is for display only.

Why How to Get the Current Date in SQL Server is important

How to Get the Current Date in SQL Server Example Usage


-- Show each product sold today with quantity
SELECT p.name, SUM(oi.quantity) AS total_sold
FROM   Orders       o
JOIN   OrderItems   oi ON oi.order_id   = o.id
JOIN   Products     p  ON p.id          = oi.product_id
WHERE  o.order_date >= CAST(GETDATE() AS date)
  AND  o.order_date <  DATEADD(day, 1, CAST(GETDATE() AS date))
GROUP BY p.name
ORDER BY total_sold DESC;

How to Get the Current Date in SQL Server Syntax


-- Basic usage
SELECT GETDATE();               -- Returns 2024-04-22 10:15:30.123
SELECT CURRENT_TIMESTAMP;       -- Same result

-- Return only the date
SELECT CAST(GETDATE() AS date); -- 2024-04-22

-- Apply formatting
SELECT FORMAT(GETDATE(),'yyyy-MM-dd HH:mm');

-- Ecommerce example: find today’s orders
SELECT id, customer_id, total_amount
FROM   Orders
WHERE  order_date >= CAST(GETDATE() AS date)
       AND order_date <  DATEADD(day, 1, CAST(GETDATE() AS date));

Common Mistakes

Frequently Asked Questions (FAQs)

Does GETDATE() return UTC or local time?

GETDATE() returns the server’s local time zone. Use SYSUTCDATETIME() for UTC.

Is GETDATE() deterministic?

No. Each call within a query can return slightly different values. Use a variable to store the value once if exact consistency is required.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo