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

DBMS16

Uploaded by

sudhanshuraj2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

DBMS16

Uploaded by

sudhanshuraj2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL NO 16:

AIM: Query Using Date Function.

Date Function:
Date functions in SQL are used to manipulate, calculate, and format date and time values.
They enable you to perform operations such as extracting parts of a date, adding or
subtracting time intervals, and formatting date outputs.
Date functions in SQL:
1. ADD_MONTHS(): Adds a specified number of months to a given date.

Syntax:
SELECT ADD_MONTHS(your_date_column, number_of_months) FROM your_table;

2. MONTHS_BETWEEN(): The MONTHS_BETWEEN function returns an estimate of


the number of months between expression1 and expression2.

Syntax:
SELECT MONTHS_BETWEEN(date1, date2) AS months_difference FROM dual;

3. LAST_DAY(): You can use the LAST_DAY() function.

Syntax:
SELECT LAST_DAY(your_date_column) AS last_day FROM your_table;

4. NEXT_DAY(): The NEXT_DAY function returns the earliest date that is later than its
DATE or DATETIME first argument, and that falls on the day of the week that its
second argument specifies.

Syntax:
NEXT_DAY(DATE,DAY);

EXAMPLES:
1. SELECT ADD_MONTHS('01-OCT-2024',12) FROM DUAL;
2. SELECT MONTHS_BETWEEN('01-OCT-2024','01-OCT-2026') FROM DUAL;
3. SELECT MONTHS_BETWEEN('01-OCT-2026','01-OCT-2024') FROM DUAL;

4. SELECT LAST_DAY('01-OCT-2024') FROM DUAL;

5. SELECT NEXT_DAY('13-OCT-2024','MON') FROM DUAL;

You might also like