DBMS LAB
(EXPERIMENT _2)
1. DATE FUNCTIONS
a) ADD_MONTHS( )
Description : ADD_MONTHS( ) function adds a number of months n to a date and
return the same day which is n months away.
Syntax : ADD_MONTHS(DATE,MONTHS)
Example Query : select ADD_MONTHS(DATE '2019-02-1',1) from dual;
Output :
b) CURRENT_DATE
Description : It returns the current date and time in the session timezone.
Syntax : CURRENT_DATE
Example Query : SELECT CURRENT_DATE FROM dual;
Output :
c) CURRENT_TIMESTAMP
Description : This function returns the date and time in the timezone of the current
sql session.
Syntax : CURRENT_TIMESTAMP
Example Query : select CURRENT_TIMESTAMP from dual;
Output :
d) DBTIMEZONE
Description : DBTIMEZONE function returns timezone of the database.
Syntax : DBTIMEZONE
Example Query : select DBTIMEZONE from dual;
Output :
e) EXTRACT( )
Description : EXTRACT function gets the specified part (day, month, year, hours,
minutes etc.) from a datetime value.
Syntax : EXTRACT(datetime_unit FROM datetime_expression1)
Example Query : SELECT EXTRACT(DAY FROM DATE '2001-03-16') FROM
dual;
Output :
f) MONTHS_BETWEEN( )
Description : MONTHS_BETWEEN( ) function returns number of months between
2 specified dates.
Syntax : MONTHS_BETWEEN( date1,date2)
Example Query :
SELECT MONTHS_BETWEEN(('01-04-1995'),('01-01-1995' ))FROM dual;
Output :
g) SYSDATE
Description : It returns current date and time set for the operating system on which
database resides.
Syntax : SYSDATE
Example Query : select SYSDATE from dual;
Output :
h) NEXT_DAY( )
Description : NEXT_DAY( ) function returns the date of day_of_the_week after d
Syntax : NEXT_DAY( date,day )
Example Query : SELECT NEXT_DAY(SYSDATE,'SUNDAY') FROM DUAL;
Output :
i) ROUND( )
Description : The ROUND( ) function takes arguments i.e., the date and the format.
It returns the date rounded to the format.
Syntax : ROUND(date,format)
Example Query :
SELECT ROUND(TO_DATE('16-MARCH-2001'),'month') ROUND FROM DUAL;
Output :
2. CONVERSION FUNCTIONS - TO_DATE and TO_CHAR.
a) TO_DATE( )
Description : converts a date which is in character string to a date value.
Syntax : TO_DATE( date in string format)
Example query : SELECT (TO_DATE('16-MAR-2001')) FROM DUAL;
Output :
b) TO_CHAR( )
Description : converts a date which is in character format to a date value.
Syntax : TO_CHAR(date,format)
Example query : SELECT TO_CHAR(SYSDATE,'DL') FROM DUAL;
Output :