Worked Examples · Example 9.21
Q.Let us use the EMPLOYEE table of CARSHOWROOM database to illustrate the working of some of the date and time functions.
a) Select the day, month number and year of joining of all employees.
b) If the date of joining is not a Sunday, then display it in the following format "Wednesday, 26, November, 1979."
Tripura TbseTextbookSubjective· 4mImportance★★★★★
38% · 36/95 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Using the real EMPLOYEE table (Table 9.12) of CARSHOWROOM: DAY(), MONTH(), YEAR() to extract date parts, and DAYNAME() together with the other three functions (no DATE_FORMAT, which the book never introduces in this chapter) to filter out Sundays and display the date as separate columns.
The real EMPLOYEE table (Table 9.12)
| EmpID | EmpName | DOB | DOJ | Designation | Salary |
|---|---|---|---|---|---|
| E001 | Rushil | 1994-07-10 | 2017-12-12 | Salesman | 25550 |
| E002 | Sanjay | 1990-03-12 | 2016-06-05 | Salesman | 33100 |
| E003 | Zohar | 1975-08-30 | 1999-01-08 | Peon | 20000 |
| E004 | Arpit | 1989-06-06 | 2010-12-02 | Salesman | 39100 |
| E006 | Sanjucta | 1985-11-03 | 2012-07-01 | Receptionist | 27350 |
| E007 | Mayank | 1993-04-03 | 2017-01-01 | Salesman | 27352 |
| E010 | Rajkumar | 1987-02-26 | 2013-10-23 | Salesman | 31111 |
(a) Day, month number, and year of joining for all employees
SELECT DAY(DOJ), MONTH(DOJ), YEAR(DOJ) FROM EMPLOYEE;
Output
| DAY(DOJ) | MONTH(DOJ) | YEAR(DOJ) |
|---|---|---|
| 12 | 12 | 2017 |
| 5 | 6 | 2016 |
| 8 | 1 | 1999 |
| 2 | 12 | 2010 |
| 1 | 7 | 2012 |
| 1 | 1 | 2017 |
| 23 | 10 | 2013 |
7 rows in set (0.03 sec)
(b) Non-Sunday joining dates as "Weekday, Day, Month, Year"
The book does not use DATE_FORMAT() here — it simply selects the four pieces (DAYNAME, DAY, MONTHNAME, YEAR) as separate columns, filtered so Sundays are excluded:
SELECT DAYNAME(DOJ), DAY(DOJ), MONTHNAME(DOJ), YEAR(DOJ)
FROM EMPLOYEE
WHERE DAYNAME(DOJ)!='Sunday';
Output …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.