SQL time-SQL Date and Time Comparison

Source: Internet
Author: User

Time Comparison in SQL Server

Example:

Select count (*) from table whereDatediff
([Second], '2017-09-18 00:00:18 ', '2017-09-18 00:00:19 ')
> 0

Description

The example statement for select datediff (day, time1, time2) is as follows:

Select datediff (day, '2017-07-23 0:41:18 ', '2017-07-23 23:41:18 ')

time1> time2 is a negative number;

time1 time2 is a positive number;

[ > day ]: Only 2010-07-23 ignore 0:41:18 '>

See the following:

Year:Select datediff ([year],Time1, time2)

Return Value:
-6
, Meaning before Subtraction

And
MySQL
On the contrary.

Month:Select datediff ([month],Time1, time2)

Day:Select datediff ([Day],Time1, time2)

Hours:Select datediff ([hour],Time1, time2)

seconds: select datediff ([second], time1, time2 )

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.