Date Function in Oracle

Oracle, PL SQL, SQL Server,

 This fun is required to manipulate date type of values and the fun are AAD_MONTHS (), MONTHS_BETWEEN (), LAST_DAY (), NEXT_DAY (), ROUND (), TRUNC (), SYSDATE, STUDENT_DATE, SYSITMESTAMP

ADD_MONTHS () :
         It is required to add a specific no. of month in a specified date.

Select add_months (’22-jan-09’, 18) from dual;
Ans 22-jul-10

MONTHS_BETWEEN ():
         It is required to display appor month difference between two specified dates
Select month_between (’22-mar-09’,’22-jan-09’) from dual;
Ans 2

 Select month_between (’28-mar-09’,’22-jan-09’) from dual;
Ans 2.1978
Select trunc (months_between (’28-mar-09’,’22-jan-09’) from dual;
Ans 2

Last_date():
        This function is required to display last day of the month’s date of a specified date

Select last_date(’22-jan-09’) from dual;
Ans – 31—jan-09

Next_date():
        This function is required to display next day of the weeks date of a specified date.

Select next_day(’17-mar-09’,’monday’) from dual;
Ans 17-mar-09
Q. write a query will display the date of Monday after six month of a specified date.
A . Select next_day(add_months(’22-jan-09’,6),’monday’) from dual;

ROUND ():
        This function required to round date month wise and year wise. If the date is rounded by month it will check the day part likewise. If the date is rounded by year it will check the month part.

Select round (to_date(’15-jan-09’),’month’) from dual;
A – 1-jan-09
Select round (to_date(’22-jan-09’),’month’) from dual;
A 1-feb -09
Select round to_date(’15-jul-09’), ‘year’) from dual;
A-  1-jan-09
        To_date is conversion function required to convert string type of date to actual date.

Trunc():
        This function is required to truncate a date monthwise or yearwise.

Select turnc (to_date(’31-dec-09’), ‘month’) from dual;
A  1-dec-09

Sysdate/ current_date :
        This function is required return current system date
Select current_date from dual;
Systimestamp :
        It required for display date and time simultaneously.
Select systimestamp from dual;

A 16-mar-09 5:30

0 Comments