Date interval: year, month, day, hour, minute, second, interval: Year

Source: Internet
Author: User

Date interval: year, month, day, hour, minute, second, interval: Year

Create a test table:

Create or replace view v ASSELECT TO_DATE ('1970-1-1 13:14:15 ', 'yyyy-MM-DD HH24: MI: ss') AS c from dual; SELECT * FROM v;

Subtract two dates to get the number of days, multiply by 24 to the hour, and so on. you can calculate the second. to calculate the month interval, use the months_between function.

The SQL code is as follows:

SELECT interval days, interval days * 24 AS interval hours, interval days * 24*60 AS interval minutes, interval days * 24*60*60 AS interval seconds, MONTHS_BETWEEN (SYSDATE, c) AS interval month, MONTHS_BETWEEN (SYSDATE, c)/24 AS interval year FROM (SELECT c, SYSDATE-c AS interval days FROM v );

The execution result is as follows:

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.