Sams Teach Yourself SQL in 24 Hours, Third Edition By Ronald R. Plew, Ryan K. Stephens
Table of Contents
Appendix C. Answers to Quizzes and Exercises
Hour 12, "Understanding Dates and Time"
Quiz Answers
1:
From where is the system date and time normally derived?
A1:
The system date is derived from the current date and time of the operating system on the host machine.
2:
List the standard internal elements of a DATETIME value.
A2:
YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND.
3:
What could be a major factor concerning the representation and comparison of date and time values if your company is an international organization?
A3:
The awareness of time zones may be a concern.
4:
Can a character string date value be compared to a date value defined as a valid DATETIME data type?
A4:
A DATETIME data type cannot be accurately compared to a date value defined as a character string. The character string must first be converted to the DATETIME data type.
Exercise Answers
1:
Type the following SQL code into the mysql> prompt to display the current date from the MySQL server:
SELECT CURRENT_DATE;
2:
Type the following SQL code into the mysql> prompt to display each employee's hire date:
SELECT EMP_ID, DATE_HIRE FROM EMPLOYEE_PAY_TBL;
3:
In MySQL, dates can be displayed in various formats using the EXTRACT function in conjunction with the MySQL date pictures. Type the following code to display on the year that each employee was hired :
SELECT EMP_ID, EXTRACT(YEAR FROM DATE_HIRE) FROM EMPLOYEE_PAY_TBL;
4:
Type the following code to display the current date along with the date that each employee was hired:
SELECT EMP_ID, DATE_HIRE, CURRENT_DATE FROM EMPLOYEE_PAY_TBL;
5:
On what day of the week was each employee hired?
A5:
SELECT EMP_ID, DAYNAME(DATE_HIRE) FROM EMPLOYEE_PAY_TBL;