Hour 12, Understanding Dates and Time

Team-Fly    

 
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; 
6:

What is today's Julian date (day of year)?

A6:
 SELECT DAYOFYEAR(CURRENT_DATE); 

Team-Fly    
Top
 


Sams Teach Yourself SQL in 24 Hours
Sams Teach Yourself SQL in 24 Hours (5th Edition) (Sams Teach Yourself -- Hours)
ISBN: 0672335417
EAN: 2147483647
Year: 2002
Pages: 275

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net