SQL Questions and Answers – SQL Dates

This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Dates”.

1. What will the output of the following statement?

SELECT DATE_ADD('1998-01-02', INTERVAL 31 DAY);

a) 1998 Feb 02
b) 02 Feb 1998
c) 1998-02-02
d) 02-02-1998
View Answer

Answer: c
Explanation: The DATE_ADD function is a synonym of ADDDATE function and it is used to add a time period to a specified date. The date is given in the YYYY-MM-DD format.
advertisement
advertisement

2. What will be the output of the following statement?

SELECT ADDTIME('1998-12-30 23:59:59.999998','1 1:1:1.000002');

a) 1999-01-01 01:01:01.000000
b) 1999-01-02 01:01:01.000000
c) 1998-12-3024:00:00.999999
d) 01:01:01.0000001999-01-01
View Answer

Answer: a
Explanation: The ADDTIME function is used to add a time period to a specified date and period. It returns both, the date and the time where date is followed by time. When we add 1 1:1:1.000002 to 1998-12-30 23:59:59.999998 we will get 1999-01-01 01:01:01.000000.

3. Which of the following function is used to return the current date of our system?
a) CUR_DATE()
b) DATE()
c) CURRENTDATE()
d) CURDATE()
View Answer

Answer: d
Explanation: The CURDATE() function is used to return the current date that is displayed by our system. It returns the date in the YYYY-MM-DD format. The CURRENT_DATE() function is a synonym of the CURDATE() function and can be used interchangeably.
advertisement

4. Which of the following function is used to return the current time of our system?
a) CUR_TIME()
b) CURTIME()
c) CURRENTTIME()
d) TIME()
View Answer

Answer: b
Explanation: The CURTIME() function is used to return the current time that is displayed by our system. It returns the time in the HH:MM:SS format. The CURRENT_TIME() function is a synonym of the CURTIME() function and can be used interchangeably.

5. What will be the output of the following statement?

advertisement
SELECT DATEDIFF('2020-11-30 23:59:59','2020-11-29');

a) -1
b) 0
c) 1
d) 00:00:01
View Answer

Answer: c
Explanation: The DATEDIFF() function is used to compute the difference between the two given dates. It returns the result in days and only the date part of the entered values is considered in the computation of the result.

6. The %c format string in the DATE_FORMAT() function is used to specify which of the following format?
a) Weekday name (Sun, Mon, …)
b) Month name (Jan, Feb, …)
c) Month number (0, 1, …)
d) Day of the month (00, 01, …)
View Answer

Answer: c
Explanation: The %c format string in the DATE_FORMAT() function is used to specify the Month number format which is given by 0 for January, 1 for February and so on.

7. Which of the following function is used to get the weekday index value for a specified date?
a) DAYNAME()
b) DAYOFWEEK()
c) DAYOFMONTH()
d) DAYOFYEAR()
View Answer

Answer: b
Explanation: The DAYOFWEEK() function is used to get the weekday index value (1 = Sunday, 2 = Monday, … , 7 = Saturday). for a specified date. The DAYNAME() function is used to return the name of the weekday for the given date. The DAYOFMONTH() & DAYOFYEAR() functions are used to return the day of month (0 to 31) and the day of year (1 to 366) respectively for the given date.

8. The NOW() function is used to return the current date and time in which of the following format?
a) HH:MM:SS DD-MM-YYYY
b) DD-MM-YYYY HH:MM:SS
c) HH:MM:SSYYYY-MM-DD
d) YYYY-MM-DD HH:MM:SS
View Answer

Answer: d
Explanation: The NOW() function is used to return the current date and time in the YYYY-MM-DD HH:MM:SS format. The YYYYMMDDHHMMSS format can also be accepted based on whether the function is used in numeric or string context.

9. What will be the output of the following statement?

SELECT QUARTER('2020-05-07');

a) 1
b) 2
c) 3
d) 4
View Answer

Answer: b
Explanation: The QUARTER function is used to return the number of the quarter in which the specified date would belong. The output range of the function is 1-4 as there are 4 quarters in a year.

10. Which of the following function is used to convert the given time into seconds?
a) TIME_TO_SEC()
b) SEC()
c) TO_SEC()
d) TIMETOSEC()
View Answer

Answer: a
Explanation: The function that is used to convert the given time into seconds is TIME_TO_SEC(). Ex –

TIME_TO_SEC(22:23:00’);

Output – 80580

Sanfoundry Global Education & Learning Series – SQL.

To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.