Oracle date calculation-INTERVAL

Source: Internet
Author: User

In addition to add_months, you can also use INTERVAL:

  1. Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.7.0
  2. ConnectedAsXxpo
  3. SQL>
  4. SQL> SELECT to_char (SYSDATE,'Yyyy/MM/DD HH24: MI: ss') Now FROM dual;
  5. NOW
  6. -------------------
  7. 06:22:00
  8. SQL> SELECT to_char (add_months (SYSDATE,-1 ),'Yyyy/MM/DD HH24: MI: ss')"1 month before"FROM dual;
  9. 1 month before
  10. -------------------
  11. 06:22:02
  12. SQL> SELECT to_char (SYSDATE + INTERVAL'-1'MONTH,'Yyyy/MM/DD HH24: MI: ss')"1 month before"FROM dual;
  13. 1 month before
  14. -------------------
  15. 06:22:04
  16. SQL> SELECT to_char (SYSDATE + INTERVAL'1-1'Year to month,'Yyyy/MM/DD HH24: MI: ss')"1 year and 1 month later"FROM dual;
  17. 1 year and 1 month later
  18. ------------------------
  19. 06:22:06
  20. SQL> SELECT to_char (SYSDATE + INTERVAL'-1-1'Year to month,'Yyyy/MM/DD HH24: MI: ss')"1 year and 1 month before"FROM dual;
  21. 1 year and 1 month before
  22. -------------------------
  23. 2010/04/20 06:22:08
  24. SQL>

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.