SQL time-related-SQL date, time comparison

Source: Internet
Author: User

Time comparison in SQL Server

Example:

Select COUNT (*) from table where DATEDIFF ([second], ' 2004-09-18 00:00:18 ', ' 2004-09-18 00:00:19 ') > 0

Description

  Select DATEDIFF (Day, time1, time2) corresponds to the following example statement

Select DATEDIFF (Day, ' 2010-07-23 0:41:18 ', ' 2010-07-23 23:41:18 ')

  time1 > time2 is negative;

  Time1 < time2 are positive;

  [Day]: will only compare 2010-07-23 ignored 0:41:18 ' Other empathy

The following distinctions:

  Year: SELECT DATEDIFF ([year],time1, time2) returns the value:-6, which indicates that the inverse of the post-subtraction is contrary to MySQL.

  Month: SELECT DATEDIFF ([month], time1, time2)

  Days: SELECT DATEDIFF ([day], time1, time2)

  Hours: SELECT DATEDIFF ([hour], time1, time2)

seconds: SELECT DATEDIFF ([second], time1, time2)

SQL time-related-SQL date, time comparison

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.