Oracle time Plus and minus

Source: Internet
Author: User


1, Function: Add_months (Date,integer)--Add the specified time to a few months

For example:

SELECT add_months (sysdate, 1) from DUAL; -The current time plus 1 months, that is, one months after the time.  SELECT add_months (Sysdate,-1) from DUAL; --The current time minus 1 months, that is, one months ago.

2, add and subtract a time for the sysdate.

For example:

SELECT sysdate + 1 from DUAL; -The current time plus 1 days, that is, a day after the time (here the 1 units are days).  SELECT SYSDATE-1 from DUAL; --The current time is reduced by 1 days, that is, one day before.  SELECT sysdate + 1/24 from DUAL; -The current time is 1 hours, or one hour later.  SELECT sysdate + 1/24/60 from DUAL; --The current time is 1 minutes, that is, one minute after the time.  SELECT sysdate + 1/24/60/60 from DUAL; --The current time is 1 seconds, which is the time after one second.

Similarly, if it is minus (-), it is a set time to push forward.

3,interval

The usage of interval is:

SELECT sysdate +/-INTERVAL ' N ' timeunit from DUAL;

Description

N: Numbers, that is, how much time to add and subtract, be sure to have single quotes.

Timeunit is: Time unit, desirable value is Year,month,day,hour,minute,second

For example:

SELECT sysdate + INTERVAL ' 1 ' days from dual;--current time plus 1 months, i.e. one months later. SELECT sysdate-interval ' 1 ' HOUR from dual;--current time minus 1 hours, or one hours ago.

This article is from the "Evan" blog, be sure to keep this source http://wenshengzhu.blog.51cto.com/5151285/1708530

Oracle time Plus and minus

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.