0% found this document useful (0 votes)
3 views

Date Functions Task

The document contains SQL queries for various date-related tasks involving employee hire dates from an 'emp' table. Tasks include filtering employees by join year, month, and day, as well as formatting dates in different styles. Additionally, it includes operations like adding days to dates and determining specific historical dates.

Uploaded by

mdsamadabdul28
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Date Functions Task

The document contains SQL queries for various date-related tasks involving employee hire dates from an 'emp' table. Tasks include filtering employees by join year, month, and day, as well as formatting dates in different styles. Additionally, it includes operations like adding days to dates and determining specific historical dates.

Uploaded by

mdsamadabdul28
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DATE FUNCTIONS TASK

=====================

Here are the SQL queries for each task:

1. Employees who joined in the year '81' using TO_CHAR()

SELECT ename, hiredate

FROM emp

WHERE TO_CHAR(hiredate, 'YY') = '81';

2. Display ename and 4-digit year from emp table using TO_CHAR()

SELECT ename, TO_CHAR(hiredate, 'YYYY') AS year

FROM emp;

3. Employees who joined in the month of December using TO_CHAR()

SELECT ename, hiredate

FROM emp

WHERE TO_CHAR(hiredate, 'MONTH') = 'DECEMBER ';

4. Employees who joined in 1980, 1982, or 1984

SELECT ename, TO_CHAR(hiredate, 'DD-MON-YYYY') AS hiredate

FROM emp

WHERE TO_CHAR(hiredate, 'YYYY') IN ('1980', '1982', '1984');

5. Employees who joined in January, March, or December

SELECT ename, hiredate

FROM emp

WHERE TO_CHAR(hiredate, 'MON') IN ('JAN', 'MAR', 'DEC');

6. Employees who joined in December 1981

SELECT ename, hiredate

FROM emp

WHERE TO_CHAR(hiredate, 'YYYY') = '1981' AND TO_CHAR(hiredate, 'MONTH') = 'DECEMBER ';

7. Employees who joined in the 1st and 4th quarters

SELECT ename, hiredate


FROM emp

WHERE TO_CHAR(hiredate, 'Q') IN ('1', '4');

8. Employees who joined in the 1st quarter of 1981

SELECT ename, hiredate

FROM emp

WHERE TO_CHAR(hiredate, 'YYYY') = '1981' AND TO_CHAR(hiredate, 'Q') = '1';

9. Employee names and the day they joined

SELECT ename, TO_CHAR(hiredate, 'DAY') AS day_of_join

FROM emp;

10. Employees who joined on a Sunday

SELECT ename, hiredate

FROM emp

WHERE TO_CHAR(hiredate, 'DAY') = 'SUNDAY ';

11. Employees who joined before the 15th of every month using TO_CHAR()

SELECT ename, hiredate

FROM emp

WHERE TO_CHAR(hiredate, 'DD') < '15';

12. Employees who joined in a leap year

SELECT ename, hiredate

FROM emp

WHERE MOD(TO_CHAR(hiredate, 'YYYY'), 4) = 0;

13. Employee records with hire dates in the Indian date format [DD/MM/YYYY]

SELECT ename, TO_CHAR(hiredate, 'DD/MM/YYYY') AS hiredate

FROM emp;

14. Employee records with hire dates in the US date format [MM/DD/YYYY]

SELECT ename, TO_CHAR(hiredate, 'MM/DD/YYYY') AS hiredate

FROM emp;

15. Convert given date string into client-required format '15-JUN-05' → '15/JUNE/05'

SELECT TO_CHAR(TO_DATE('15-JUN-05', 'DD-MON-YY'), 'DD/JUNE/YY') AS formatted_date

FROM dual;

16. Add 5 days to the given date '18-APR-08'


SELECT TO_DATE('18-APR-08', 'DD-MON-YY') + 5 AS new_date

FROM dual;

17. Add 5 days to the given date '10-04-08'

SELECT TO_DATE('10-APR-08', 'DD-MON-YY') + 5 AS new_date

FROM dual;

18. Display the year from '15-AUG-2024'

SELECT TO_CHAR(TO_DATE('15-AUG-2024', 'DD-MON-YYYY'), 'YYYY') AS year

FROM dual;

19. Find which day India got independence using TO_CHAR()

SELECT TO_CHAR(TO_DATE('15-AUG-1947', 'DD-MON-YYYY'), 'DAY') AS day

FROM dual;

You might also like