0
0
MysqlHow-ToBeginner · 3 min read

How to Use CURDATE() in MySQL: Syntax and Examples

In MySQL, use the CURDATE() function to get the current date in 'YYYY-MM-DD' format. It returns the date without the time part and is useful for date comparisons and queries.
📐

Syntax

The CURDATE() function has no parameters and returns the current date as a value in 'YYYY-MM-DD' format.

Use it simply as CURDATE() in your SQL queries.

sql
SELECT CURDATE();
Output
2024-06-15
💻

Example

This example shows how to select the current date using CURDATE() and how to use it in a WHERE clause to find records from today.

sql
CREATE TABLE events (
  id INT PRIMARY KEY,
  event_name VARCHAR(50),
  event_date DATE
);

INSERT INTO events VALUES
(1, 'Meeting', '2024-06-15'),
(2, 'Conference', '2024-06-14');

SELECT event_name, event_date FROM events WHERE event_date = CURDATE();
Output
event_name | event_date ----------|------------ Meeting | 2024-06-15
⚠️

Common Pitfalls

  • Using CURDATE() when you need the current date and time; for that, use NOW() instead.
  • Comparing CURDATE() with datetime columns without converting them can cause no matches because of the time part.
  • Not realizing CURDATE() returns the server's current date, which may differ from the client time zone.
sql
/* Wrong: comparing CURDATE() with datetime column directly */
SELECT * FROM events WHERE event_date_time = CURDATE();

/* Right: use DATE() to extract date part from datetime */
SELECT * FROM events WHERE DATE(event_date_time) = CURDATE();
📊

Quick Reference

FunctionDescriptionReturns
CURDATE()Returns current date'YYYY-MM-DD' (date)
NOW()Returns current date and time'YYYY-MM-DD HH:MM:SS' (datetime)
CURRENT_DATESynonym for CURDATE()'YYYY-MM-DD' (date)

Key Takeaways

Use CURDATE() to get the current date without time in MySQL.
CURDATE() returns the date in 'YYYY-MM-DD' format as a DATE type.
For current date and time, use NOW() instead of CURDATE().
When comparing with datetime columns, extract the date part using DATE().
CURDATE() reflects the MySQL server's date, which may differ from client time.