First of all, thanks to the author's hard Sweat to bring us a summary, because the date function operation on peacetime use is really very common, so collection for later use.
Original Sticker Address: http://www.cnblogs.com/xiao-yu/archive/2011/05/24/2055967.html
Both date and timestamp can be added and reduced.
There are three ways to manipulate different time types for the current date Gagnin, month, day, hour, minute, and second:
1 add hours, minutes and seconds using built-in functions Numtodsinterval
2 plus a simple number to increase the day
3 use built-in function add_months to increase year and month
Cases:
Add one hours to the current date:
Select sysdate, Sysdate+numtodsinterval (1 from dual; Sysdate sysdate+numtodsinte ——————-——————--ten: : +--:19
Add 50 minutes to the current date
Select sysdate, Sysdate+numtodsinterval ( from dual; Sysdate sysdate+numtodsinte ——————-——————--ten: The following: 12-Ten
Add 45 seconds to the current date
Select sysdate, Sysdate+numtodsinterval ( from dual; Sysdate sysdate+numtodsinte ——————-——————--ten: (+): $:51
Add 3 days to the current date
Select sysdate, sysdate+3 from dual; Sysdate sysdate+3——————-——————--ten: +:46-£º
Add 4 months to the current date
Select sysdate, Add_months (Sysdate,4 from dual; Sysdate add_months (sysdate,——————-——————--ten: :---------- £ º
2 year increase in current date
Select sysdate, Add_months (sysdate,2 from dual; Sysdate add_months (sysdate,——————-——————--ten:42 :+-:£ º
The operation method of timestamp is similar to the above;
Ask for the difference of two dates:
Example: To find the difference between the 21:23:34 and the current time in 2007-5-23.
Select sysdate-to_date ('20070523: £º fromdual;D t-- --1240.01623
If the two date is directly subtracted, the result is a data type, we may want to get two date difference in the expression form:
* * * * * * * * * * * *:* *:* *
Sql>SELECT Numtoyminterval (Months_between (DT1, DT2), ' month ') Mon,2Numtodsinterval (dt1-(Add_months (Dt2,trunc (Months_between (DT1, DT2))), ' Day ') Day3From (SELECT sysdate DT1,4To_date ('20070523 +: at: the, ' yyyy-mm-DD Hh24:mi:ss ') DT25From DUAL)6 ; MON Day —————-———————-+000000003-Geneva+000000021 xx: +:15.999999999
namely: 3 years 4 months 21 days 00:40:15.99999999
Oracle date plus minus "go"