DBMS16
DBMS16
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;
Syntax:
SELECT MONTHS_BETWEEN(date1, date2) AS months_difference FROM dual;
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;