Introduction
Working with dates and times is crucial for managing databases, especially with MySQL. This quiz tests your knowledge of MySQL date functions, which help retrieve, manipulate, and format date values. Whether you’re a beginner or an experienced developer, these questions challenge your understanding of date handling in MySQL. Let’s dive in and see how well you know MySQL’s date functions!

Question 1
What function retrieves the current date and time in MySQL?
A) CURRENT_DATE()
B) NOW()
C) GETDATE()
D) Both A and B
Question 2
Which function returns the difference in days between two date values?
A) DATEDIFF()
B) TIMEDIFF()
C) DATEDIFF_TIMES()
D) DATE_DIFF()
Question 3
How can you add 45 days to a given date in MySQL?
A) ADD_DATE(your_date, INTERVAL 45 DAY)
B) your_date + INTERVAL 45 DAY
C) DATE_ADD(your_date, INTERVAL 45 DAY)
D) Both B and C
Question 4
What will be the output of the query below?
SELECT DATE_SUB('2023-10-31', INTERVAL 7 DAY);
A) 2023-10-24
B) 2023-10-30
C) 2023-11-07
D) 2023-10-25
Question 5
Which function can convert a string to a date format?
A) TO_DATE()
B) STR_TO_DATE()
C) CONVERT_DATE()
D) CAST_DATE()
Question 6
What will SELECT CURDATE(); return?
A) The current date
B) The current date and time
C) The current UNIX timestamp
D) The current time
Question 7
What does the YEAR() function do?
A) Retrieves the year part of a date
B) Retrieves the month part of a date
C) Retrieves the day part of a date
D) None of the above
Question 8
How do you extract the month from a date in MySQL?
A) MONTH(your_date)
B) EXTRACT(MONTH FROM your_date)
C) GET_MONTH(your_date)
D) Both A and B
Question 9
What will be the output of the following query?
SELECT NOW() + INTERVAL 1 HOUR;
A) Adds 1 day to the current time
B) Adds 1 hour to the current time
C) Adds 1 minute to the current time
D) None of the above
Question 10
Which keyword is used to indicate the number of units to add or subtract with DATE_ADD() and DATE_SUB()?
A) SET
B) FOR
C) INTERVAL
D) ADDITION
Question 11
Which formula will retrieve the last day of the month for a given date?
A) LAST_DAY(your_date)
B) END_OF_MONTH(your_date)
C) FINAL_DAY(your_date)
D) LASTM(your_date)
Question 12
What is the purpose of the UNIX_TIMESTAMP() function?
A) Converts a date to a UNIX timestamp
B) Converts a UNIX timestamp to a date
C) Retrieves the current time in UTC
D) None of the above
Question 13
How can you round a date to the nearest hour in MySQL?
A) ROUND_DATE(your_date)
B) FLOOR(your_date)
C) DATE_FORMAT(your_date, '%Y-%m-%d %H:00:00')
D) ROUND(your_date)
Question 14
What format does DATE_FORMAT() allow for outputting date values?
A) Only numeric formats
B) Custom formats with format_string
C) Date only
D) Time only
Question 15
Which function will give you the current year in MySQL?
A) CURRENT_YEAR()
B) YEAR(NOW())
C) GET_YEAR()
D) YEAR(CURDATE())
Question 16
What will the following command return?
SELECT DATEDIFF('2023-10-31', '2023-10-01');
A) 30
B) 31
C) 29
D) 24
Question 17
What does NOW() return?
A) Current date in UTC
B) Current server date and time
C) Current UNIX timestamp
D) Current date only
Question 18
Which function checks if a string is a valid date format?
A) IS_DATE()
B) DATE_CHECK()
C) STR_TO_DATE()
D) CHECK_DATE()
Question 19
What will the output of the following SQL command be?
SELECT WEEK('2023-10-31');
A) The week number of the year for that date
B) The total number of weeks in the year
C) The year for that date
D) The current week’s number
Question 20
How do you find the time difference between two datetime values?
A) TIMEDIFF()
B) DATEDIFF()
C) TIME_SUB()
D) TIME_DIFF()
Answers
- D) Both A and B
- A)
DATEDIFF() - D) Both B and C
- A)
2023-10-24 - B)
STR_TO_DATE() - A) The current date
- A) Retrieves the year part of a date
- D) Both A and B
- B) Adds 1 hour to the current time
- C)
INTERVAL - A)
LAST_DAY(your_date) - A) Converts a date to a UNIX timestamp
- C)
DATE_FORMAT(your_date, '%Y-%m-%d %H:00:00') - B) Custom formats with
format_string - B)
YEAR(NOW()) - A)
30 - B) Current server date and time
- C)
STR_TO_DATE() - A) The week number of the year for that date
- A)
TIMEDIFF()
References







You must be logged in to post a comment.