Bird
Raised Fist0
MySQLquery~20 mins

NOW, CURDATE, CURTIME in MySQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Date and Time Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
1:30remaining
What does the query return?
Consider the query:
SELECT CURDATE();

What is the output format of this query?
MySQL
SELECT CURDATE();
AA string in 'HH:MM:SS' format representing current time
BA string in 'YYYY-MM-DD' format representing today's date
CA datetime value including date and time
DAn integer representing the current timestamp
Attempts:
2 left
💡 Hint
CURDATE() returns only the date part, not time.
❓ query_result
intermediate
1:30remaining
What is the output of NOW()?
Given the query:
SELECT NOW();

What does this function return?
MySQL
SELECT NOW();
AOnly the current time in 'HH:MM:SS' format
BOnly the current date in 'YYYY-MM-DD' format
CThe current date and time as a datetime value in 'YYYY-MM-DD HH:MM:SS' format
DThe Unix timestamp as an integer
Attempts:
2 left
💡 Hint
NOW() returns both date and time.
❓ query_result
advanced
1:30remaining
What is the output of CURTIME()?
What does the query below return?
SELECT CURTIME();
MySQL
SELECT CURTIME();
AThe current time as a string in 'HH:MM:SS' format
BThe current date as a string in 'YYYY-MM-DD' format
CThe current date and time as a datetime value
DThe current Unix timestamp as an integer
Attempts:
2 left
💡 Hint
CURTIME() returns only the time part.
🧠 Conceptual
advanced
1:30remaining
Difference between NOW() and CURDATE()
Which statement correctly describes the difference between NOW() and CURDATE() in MySQL?
ANOW() returns current date and time; CURDATE() returns only the current date
BNOW() returns only the current time; CURDATE() returns current date and time
CNOW() returns Unix timestamp; CURDATE() returns date as string
DNOW() returns only the current date; CURDATE() returns only the current time
Attempts:
2 left
💡 Hint
Think about what each function returns: date, time, or both.
📝 Syntax
expert
2:00remaining
Which query will cause an error?
Identify which of the following queries will cause a syntax error in MySQL.
ASELECT NOW();
BSELECT CURDATE();
CSELECT CURTIME();
DSELECT NOW(5);
Attempts:
2 left
💡 Hint
Check if NOW() accepts any arguments.

Practice

(1/5)
1. What does the MySQL function NOW() return?
easy
A. Only the current date
B. The current date and time
C. Only the current time
D. The current year

Solution

  1. Step 1: Understand the function purpose

    NOW() is designed to return both date and time together.
  2. Step 2: Compare with other functions

    CURDATE() returns only date, CURTIME() returns only time, so NOW() returns both.
  3. Final Answer:

    The current date and time -> Option B
  4. Quick Check:

    NOW() = current date + time [OK]
Hint: NOW() gives date and time together [OK]
Common Mistakes:
  • Confusing NOW() with CURDATE()
  • Thinking NOW() returns only time
  • Assuming NOW() returns only year
2. Which of the following is the correct syntax to get only the current date in MySQL?
easy
A. SELECT CURDATE();
B. SELECT NOW();
C. SELECT CURRENT_TIME();
D. SELECT CURTIME();

Solution

  1. Step 1: Identify function for current date

    CURDATE() returns only the current date in MySQL.
  2. Step 2: Check other options

    NOW() returns date and time, CURRENT_TIME() and CURTIME() return only time.
  3. Final Answer:

    SELECT CURDATE(); -> Option A
  4. Quick Check:

    CURDATE() = current date only [OK]
Hint: Use CURDATE() for date only [OK]
Common Mistakes:
  • Using NOW() when only date is needed
  • Confusing CURTIME() with CURDATE()
  • Using CURRENT_TIME() for date
3. What will be the output of this query if run at exactly 2024-06-15 14:30:45?
SELECT NOW(), CURDATE(), CURTIME();
medium
A. '2024-06-15 00:00:00', '14:30:45', '2024-06-15'
B. '2024-06-15', '14:30:45', '2024-06-15 14:30:45'
C. '14:30:45', '2024-06-15 14:30:45', '2024-06-15'
D. '2024-06-15 14:30:45', '2024-06-15', '14:30:45'

Solution

  1. Step 1: Understand each function output

    NOW() returns full date and time, CURDATE() returns date only, CURTIME() returns time only.
  2. Step 2: Match given time values

    At 2024-06-15 14:30:45, NOW() = '2024-06-15 14:30:45', CURDATE() = '2024-06-15', CURTIME() = '14:30:45'.
  3. Final Answer:

    '2024-06-15 14:30:45', '2024-06-15', '14:30:45' -> Option D
  4. Quick Check:

    NOW() = full datetime, CURDATE() = date, CURTIME() = time [OK]
Hint: NOW() full, CURDATE() date, CURTIME() time [OK]
Common Mistakes:
  • Mixing order of outputs
  • Assuming CURTIME() returns date
  • Confusing NOW() with CURDATE()
4. Identify the error in this query:
SELECT NOW, CURDATE(), CURTIME();
medium
A. NOW is missing parentheses
B. CURDATE() should be CURTIME()
C. CURTIME() is misspelled
D. No error, query is correct

Solution

  1. Step 1: Check function syntax

    MySQL functions require parentheses even if no arguments are passed. NOW without () is invalid.
  2. Step 2: Verify other functions

    CURDATE() and CURTIME() have correct syntax with parentheses.
  3. Final Answer:

    NOW is missing parentheses -> Option A
  4. Quick Check:

    Functions need () even if empty [OK]
Hint: Always use () with MySQL functions [OK]
Common Mistakes:
  • Omitting parentheses for functions
  • Assuming functions can be called without ()
  • Thinking CURDATE() is incorrect
5. You want to insert the current date and time into a table's created_at column. Which query correctly uses MySQL functions to do this?
hard
A. INSERT INTO logs (created_at) VALUES (CURDATE());
B. INSERT INTO logs (created_at) VALUES (CURTIME());
C. INSERT INTO logs (created_at) VALUES (NOW());
D. INSERT INTO logs (created_at) VALUES ('CURDATE()');

Solution

  1. Step 1: Understand the column data type

    created_at usually stores full date and time, so we need a function that returns both.
  2. Step 2: Choose correct function

    NOW() returns current date and time, CURDATE() returns only date, CURTIME() only time, and quoting function names inserts strings, not values.
  3. Final Answer:

    INSERT INTO logs (created_at) VALUES (NOW()); -> Option C
  4. Quick Check:

    Use NOW() for full datetime insert [OK]
Hint: Use NOW() to insert full date and time [OK]
Common Mistakes:
  • Using CURDATE() when time is needed
  • Using CURTIME() when date is needed
  • Inserting function name as string
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard