Oracle SQL

How to Use Oracle ADD_MONTHS and CURRENT_DATE Functions in SQL Queries

How to Use Oracle ADD_MONTHS and CURRENT_DATE Functions in SQL Queries
Avatar of shohal
Written by shohal

ADD_MONTHS

Syntax

ADD_MONTHS(date_expression, month)

Examples

  1. Add a number of months to a date

The following example adds 1 month to 29-FEB-2016:

   SELECT
   ADD_MONTHS( DATE'2016-02-29', 1 )
   FROM
dual;
   The result is:
   31-MAR-16
B)  Add a negative number of months to a date
 
   The following statement illustrates the effect of using a negative month
   for the ADD_MONTH() function:
   SELECT
   ADD_MONTHS( DATE'2016-03-31', -1 )
   FROM
dual;
   Here is the result:
   29-FEB-16
C)  Get the last day of the last month
 
The following statement returns the last day of the last month.
   SELECT
   LAST_DAY( ADD_MONTHS(SYSDATE , - 1 ) )
   FROM
   dual;
LAST_DAY
---------
31-MAY-22


CURRENT_DATE

Syntax

CURRENT_DATE

Examples

The following statement changes the default date format to a new one that includes the time data:
 
   ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
   To find out the session time zone, you use the SESSIONTIMEZONE function    as follows:
   SELECT
   SESSIONTIMEZONE
   FROM
  DUAL;
 
Currently, the session time zone is set to -07:00
To get the current date in the session time zone, you use the following statement:
   
   SELECT
  CURRENT_DATE
   FROM
 DUAL;
Here is the output:
   06-AUG-2017 19:43:44
First, set the session time zone to -09:00:
   ALTER SESSION SET TIME_ZONE = '-09:00';
Second, get the current date of in the session time zone:
   06-AUG-2017 17:45:33
🚀
How to Use Oracle ADD_MONTHS and CURRENT_DATE Functions in SQL Queries | TechTweet

If you’d like me to proceed with any of these, please just let me know from the site techtweet.xyz! Also if you need to learn something new than subscribe YouTube : ASP.NET With SQL SERVER

About the author

Avatar of shohal

shohal

I have profession and personal attachment with custom ERP Software development, Business Analysis, Project Management and Implementation almost (36) ,also Oracle Apex is my all-time favorite platform to developed the software. Moreover i have some website development experience with WordPress. For hand on networking experience DevOps and CCNA, it create me a full package. Here are some core programming language with networking course i have been worked: Oracle SQL ,PL/SQL,Oracle 19c Database , Oracle Apex 20.1,WordPress,Asp.Net ,MS SQL ,CCNA ,Dev Ops, SAP SD