How to Get Current Date in MySQL

Galaxy Glossary

How do I get today’s date in MySQL?

CURRENT_DATE (or CURDATE) returns the server’s current date as a DATE value without the time part.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Why use CURRENT_DATE in MySQL?

Grab today’s date directly from the server clock, ensuring every user and application sees the same value at query time. Ideal for audit columns, daily reports, and time-based filters.

What is the basic syntax?

Run SELECT CURRENT_DATE; or the function form SELECT CURRENT_DATE();.Both return YYYY-MM-DD.

How do I filter today’s orders?

Combine CURRENT_DATE with a WHERE clause:
SELECT * FROM Orders WHERE order_date = CURRENT_DATE; This lists purchases placed since midnight.

How can I find customers created this week?

Use DATE_SUB to define the range:
SELECT * FROM Customers WHERE created_at BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) AND CURRENT_DATE;

Can I format the returned date?

Wrap the function with DATE_FORMAT:
SELECT DATE_FORMAT(CURRENT_DATE, '%M %d, %Y') AS pretty_date;June 05, 2024.

How do I insert the current date into a table?

Let MySQL handle it: INSERT INTO Orders (customer_id, order_date, total_amount) VALUES (9, CURRENT_DATE, 149.00);

Best practices for CURRENT_DATE

Store dates in UTC for global apps, test daylight-saving transitions, and avoid hard-coded literals in recurring jobs.

Common mistakes

Using NOW() when the time part is unwanted

NOW() returns a DATETIME; implicit casts may hide time zones.Use CURRENT_DATE for pure dates.

Forgetting parentheses with CURDATE()

Both CURRENT_DATE and CURDATE() work, but CURDATE without () is invalid. Add parentheses or switch to CURRENT_DATE.

Quick reference recap

SELECT CURRENT_DATE; provides a reliable, timezone-aware value for all date-only needs.

.

Why How to Get Current Date in MySQL is important

How to Get Current Date in MySQL Example Usage


-- List products sold today with quantities
SELECT p.name, oi.quantity
FROM OrderItems oi
JOIN Orders o  ON o.id = oi.order_id
JOIN Products p ON p.id = oi.product_id
WHERE o.order_date = CURRENT_DATE;

How to Get Current Date in MySQL Syntax


-- Return today’s date
a) SELECT CURRENT_DATE;
   -- or
b) SELECT CURRENT_DATE();

-- Filter orders placed today
SELECT *
FROM Orders
WHERE order_date = CURRENT_DATE;

-- Insert a new order with today’s date
INSERT INTO Orders (customer_id, order_date, total_amount)
VALUES (42, CURRENT_DATE, 99.99);

-- Compare stock arrivals within last 30 days
SELECT *
FROM Products
WHERE created_at >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY);

Common Mistakes

Frequently Asked Questions (FAQs)

Is CURRENT_DATE affected by session time zone?

Yes. MySQL evaluates CURRENT_DATE using the current session’s time zone. Set SET time_zone for consistent results.

Can I use CURRENT_DATE in a generated column?

No. Generated columns must be deterministic. Use a BEFORE INSERT/UPDATE trigger to populate the column with CURRENT_DATE.

What’s the difference between CURRENT_DATE and CURDATE()?

Nothing—both return the same DATE value. CURRENT_DATE is ANSI-SQL, CURDATE() is MySQL-specific.

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
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.