0
0
MySQLquery~10 mins

NOW, CURDATE, CURTIME in MySQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - NOW, CURDATE, CURTIME
Call NOW()
Return current date and time
Call CURDATE()
Return current date only
Call CURTIME()
Return current time only
Use results in query or display
Each function fetches the current date/time from the system: NOW() gives date and time, CURDATE() gives only date, CURTIME() gives only time.
Execution Sample
MySQL
SELECT NOW() AS current_datetime,
       CURDATE() AS current_date,
       CURTIME() AS current_time;
This query returns the current date and time, current date only, and current time only.
Execution Table
StepFunction CalledReturned ValueExplanation
1NOW()2024-06-15 14:23:45Returns full current date and time
2CURDATE()2024-06-15Returns only the current date
3CURTIME()14:23:45Returns only the current time
4Query Result{"current_datetime":"2024-06-15 14:23:45","current_date":"2024-06-15","current_time":"14:23:45"}Final output row with all three values
💡 All functions return current system date/time values at query execution time
Variable Tracker
VariableStartAfter NOW()After CURDATE()After CURTIME()Final
current_datetimeNULL2024-06-15 14:23:452024-06-15 14:23:452024-06-15 14:23:452024-06-15 14:23:45
current_dateNULLNULL2024-06-152024-06-152024-06-15
current_timeNULLNULLNULL14:23:4514:23:45
Key Moments - 3 Insights
Why does NOW() return both date and time, but CURDATE() only returns the date?
NOW() returns the full timestamp including date and time as shown in execution_table row 1, while CURDATE() extracts only the date part as shown in row 2.
If I run the query at different times, will the results change?
Yes, because these functions fetch the current system date/time at the moment of query execution, so values update each time you run the query (see exit_note).
Can CURTIME() return a date value?
No, CURTIME() returns only the time portion as shown in execution_table row 3, it never returns a date.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what does CURDATE() return at step 2?
ACurrent time only
BCurrent date only
CCurrent date and time
DNULL
💡 Hint
Check execution_table row 2 under Returned Value
At which step does the function return only the time portion?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at execution_table row 3 for CURTIME() output
If you want both date and time in your query result, which function should you use?
ACURDATE()
BCURTIME()
CNOW()
DNone of these
💡 Hint
Refer to execution_table row 1 for NOW() output
Concept Snapshot
NOW() returns current date and time.
CURDATE() returns current date only.
CURTIME() returns current time only.
All fetch system time at query execution.
Use them to get current timestamps in queries.
Full Transcript
This lesson shows how MySQL functions NOW(), CURDATE(), and CURTIME() work. NOW() returns the full current date and time, CURDATE() returns only the date, and CURTIME() returns only the time. Each function gets the current system date/time when the query runs. The example query selects all three values. The execution table shows each function call and its returned value. Variables track how each value is assigned step-by-step. Key moments clarify common confusions like why NOW() returns both date and time but CURDATE() does not. The quiz tests understanding by asking about specific steps and outputs. This helps beginners see exactly what each function returns and when.