← Back to MySQL Course | Chapter 13: Date & Numeric Functions | Lesson 3 of 6

NOW CURDATE CURTIME

The Current Date and Time with NOW

NOW returns both the current date and time together as a single value, down to the second, making it the go-to function for timestamping exactly when a row was inserted or an event occurred.

Example: The Current Date and Time with NOW

sql
SELECT NOW() AS current_datetime;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

The Current Date with CURDATE

CURDATE returns only today's date with no time component at all, which is the right choice when you care about which day something happened but the exact hour or minute is irrelevant, like a billing date.

Example: The Current Date with CURDATE

sql
SELECT CURDATE() AS today;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

The Current Time with CURTIME

CURTIME returns only the current time with no date attached, useful for logging things like daily opening/closing hours or comparing against a recurring daily schedule rather than a specific calendar day.

Example: The Current Time with CURTIME

sql
SELECT CURTIME() AS right_now;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Saving Current Dates to Tables

These functions are commonly wired up as default column values, so MySQL automatically stamps new rows with the moment they were created without the application needing to calculate and send a timestamp itself.

Example: Saving Current Dates to Tables

sql
CREATE TABLE logs (id INT, message TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP);
INSERT INTO logs (id, message) VALUES (1, 'User signed up');
SELECT * FROM logs;

Simple Date Math with Intervals

You can add or subtract intervals directly against the current date, such as CURDATE() + INTERVAL 7 DAY, to compute things like a one-week deadline or trial expiration without manual date arithmetic in application code.

Example: Simple Date Math with Intervals

sql
SELECT CURDATE() + INTERVAL 7 DAY AS trial_expires;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.