Skip to content
Worked Examples · Example 1.4

Q.Using the EMPLOYEE table of the CARSHOWROOM database to illustrate the working of 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 format "Wednesday, 26, November, 1979" (i.e. DayName, Day, MonthName, Year).
Uttar Pradesh UpmspTextbookSubjective· 3mImportance★★★★★
18% · 7/40 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 →

Extract day/month/year from the EMPLOYEE table's DOJ column with DAY()/MONTH()/YEAR(), then use DAYNAME() in a WHERE clause to exclude Sunday joiners while displaying the full date in words.

This is a code/query task on the real EMPLOYEE table of CARSHOWROOM:

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() and YEAR() each pull one numeric component out of the DOJ date column:

SELECT DAY(DOJ), MONTH(DOJ), YEAR(DOJ) FROM EMPLOYEE;

Applied to every employee's DOJ, this gives one row per employee:

DAY(DOJ)MONTH(DOJ)YEAR(DOJ)
12122017
562016
811999
2122010
172012
112017
23102013

(b) The request is to show the FULL date in words ("Wednesday, 26, November, 1979") but only for employees who didn't join on a Sunday. DAYNAME() returns the weekday as a word, so it does double duty here — once in the WHERE clause to exclude Sundays, and once in the SELECT list to display it:

SELECT DAYNAME(DOJ), DAY(DOJ), MONTHNAME(DOJ), YEAR(DOJ)
FROM EMPLOYEE
WHERE DAYNAME(DOJ)!='Sunday';

Checking each DOJ's weekday: 2017-12-12 → Tuesday, 2016-06-05 → Sunday, 1999-01-08 → Friday, 2010-12-02 → Thursday, 2012-07-01 → Sunday, 2017-01-01 → Sunday, 2013-10-23 → Wednesday. The three Sunday joiners (Sanjay, Sanjucta, Mayank) are filtered out, leaving 4 rows:

| DAYNAME(DOJ) | DAY(DOJ) | MONTHNAME(DOJ) | YEAR(DOJ) |

|---|---|---|---| …

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.