Reputation: 83
I have a field next_repay_date
as varchar2(11)
.
I need to get the date after 2 days.
Suppose I am having next_repay_date as 25-Sep-2011
as varchar2(11)
, I should get a result as 27-Sep-2011
Please suggest a solution?
Upvotes: 2
Views: 330
Reputation: 146189
Date arithmetic is really simply in Oracle, providing we have an actual DATE to work with. So the first step is to cast your column to a DATE datatype, and then you can add or subtract days from it.
SQL> select to_date('27-SEP-2011', 'DD-MON-YYYY') + 2
2 from dual
3 /
TO_DATE('
---------
29-SEP-11
SQL>
Upvotes: 3
Reputation: 38200
Since you are using Oracle this could be done as
SELECT to_date('25-Sep-2007', 'dd-MON-RRRR') + 2 from dual
Upvotes: 3
Reputation: 11581
Step 1, use the correct type for dates, that is, type DATE.
Step 2, use yourdate + INTERVAL 2 DAY (mysql).
Upvotes: 3
Reputation: 32651
Dates should not be held in char fields - use a Date or datetime
Then add two days - which I think is DBMS sepcific
Upvotes: 4