DB2 SQL calculates time difference and formatting times

Source: Internet
Author: User
Format time

DB2 format time used by To_char (TIMESTAMP (' 2017-10-24 21:18:12 '), ' yyyy-mm-dd ');

Test Sql:select To_char (TIMESTAMP (' 2017-10-24 21:18:12 '), ' Yyyy-mm-dd ') from SYSIBM. DUAL;

Calculate Time Difference

DB2 Calculation time difference use

Timestampdiff (<n>, char (timestamp (' 2017-12-24 00:00:10 ')-timestamp (' 2017-12-24 00:00:05 ')))

Test sql:

Select Timestampdiff (2, char (timestamp (' 2017-12-24 00:00:10 ')-timestamp (' 2017-12-24 00:00:05 ')) from SYSIBM. DUAL;


For <n>, you can use the following values instead to indicate the time unit of the result:
1 = decimal part of seconds
2 = Seconds
4 = Minute
8 = When
16 = Day
32 = Week
64 = Month
128 = Quarter
256 = Year

DB2 SQL calculates time difference and formatting times

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.