Skip to content
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."
Yanam CbseNCERTSubjective· 4mImportance★★★★★
38% · 36/95 Questions
🔒 Locked · start free trial →

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)

EmpIDEmpNameDOBDOJDesignationSalary
E001Rushil1994-07-102017-12-12Salesman25550
E002Sanjay1990-03-122016-06-05Salesman33100
E003Zohar1975-08-301999-01-08Peon20000
E004Arpit1989-06-062010-12-02Salesman39100
E006Sanjucta1985-11-032012-07-01Receptionist27350
E007Mayank1993-04-032017-01-01Salesman27352
E010Rajkumar1987-02-262013-10-23Salesman31111

(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)
12122017
562016
811999
2122010
172012
112017
23102013

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.