Java bro

Java tutorial

Sql queries

Add days to sql date

In this tutorial we are going to learn how to add days, months and time to string date . First we have to convert string date to sql date using TO_DATE function . See the below example.

Syntax:

SELECT TO_DATE(‘STRING DATE’ , ‘STRING DATE FORMAT’) AS SYS_DATE FROM DUAL;
Example:

SELECT TO_DATE(’01/02/2016′ , ‘DD/MM/YYYY’) from DUAL;


Output :

SYSDATE
01-FEB-16


See the above exmaple , two parameters passed to TO_DATE function . First parameter is string date that we want to convert . Second parameter is the format that our string contains.
For example , if our string date is ‘January 13 2015’ then date format that should be passed to TO_DATE function is ‘MONTH DD YYYY’ .

adding 3 days to string date:

SELECT TO_CHAR(TO_DATE(’01/02/2016′ , ‘DD/MM/YYYY’) +3 , ‘MONTH:DD:YEAR’) AS FUTURE_DATE from DUAL;


Output :

Comments are Closed

Theme by Anders Norén