Date Plus and minus in Oracle

Source: Internet
Author: User

Addition
Select Sysdate,add_months (sysdate,12) from dual; --plus 1 years
Select Sysdate,add_months (sysdate,1) from dual; --Add January
Select Sysdate,to_char (sysdate+7, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 weeks
Select Sysdate,to_char (sysdate+1, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 days
Select Sysdate,to_char (sysdate+1/24, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 hours
Select Sysdate,to_char (sysdate+1/24/60, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 minutes
Select Sysdate,to_char (sysdate+1/24/60/60, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 secondsSubtraction
Select Sysdate,add_months (sysdate,-12) from dual; -Minus 1 years
Select Sysdate,add_months (sysdate,-1) from dual; --Minus January
Select Sysdate,to_char (sysdate-7, ' Yyyy-mm-dd HH24:MI:SS ') from dual; -Minus 1 weeks
Select Sysdate,to_char (sysdate-1, ' Yyyy-mm-dd HH24:MI:SS ') from dual; -Minus 1 days
Select Sysdate,to_char (sysdate-1/24, ' Yyyy-mm-dd HH24:MI:SS ') from dual; -Minus 1 hours
Select Sysdate,to_char (sysdate-1/24/60, ' Yyyy-mm-dd HH24:MI:SS ') from dual; -Minus 1 minutes
Select Sysdate,to_char (sysdate-1/24/60/60, ' Yyyy-mm-dd HH24:MI:SS ') from dual; -Minus 1 seconds the date and date cannot be added together with a date and number

Sql> select sysdate+1 from dual; Date and date can be subtracted

Sql> select Sysdate-sysdate from dual;
Add_months (d,x)
Returns the D date plus the date after x months
Last_day (D)
Returns the date of the last day of the month that contains the date D
Add_months (sysdate,1) plus a month

Add_months (sysdate,-1) minus one months

Sysdate+1 plus one day -------------------------------------------------------------------------------
Months_between (D1,D2)
Returns the number of months between D1 and D2

New_time (D,Z1,Z2)
Returns the time in time zone Z1 when D is Z2

Next_day (D,s)
Returns the next day that satisfies the condition s
S is the day of the week

Round (D,F) 
      Date D is rounded by format F    
         
  Sysdate         Returns the current time of the database    
        
  Trunc (d,f)     
      truncate time by format F D   
        In addition: the date can be directly added    
  such as:sysdate    +1,sysdate  -1 ------------------------------------------------------------sysdate+1 plus One day
SYSDATE+1/24 plus 1 hours
SYSDATE+1/(24*60) plus 1 minutes
SYSDATE+1/(24*60*60) plus 1 seconds

Date Plus and minus in Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.