SQL Server Date Processing DateDiff

Source: Internet
Author: User

Grammar:

DATEDIFF (datepart,startdate,enddate)

The datepart parameter can be the following value:

Date-part:year | Quarter | Month | Week | Day | Hour | Minute | Second | Millisecond

The parameter date-part specifies the date portion of the interval to be measured.

DatePart Abbreviations
Years YY, yyyy
Quarter QQ, Q
Month MM, M
The day of the year Dy, y
Day DD, D
Week WK, WW
Week DW, W
Hours hh
Minutes MI, n
Seconds SS, S
Milliseconds Ms
Subtle MCs
Na-Sec Ns


e.g.:

Choose:

The following statement returns 1:select DateDiff (hour, ' 4:00AM ', ' 5:50am ')

The following statement returns 102:select DateDiff (month, ' 1987/05/02 ', ' 1995/11/15 ')

The following statement returns 0:select DateDiff (day, ' 00:00 ', ' 23:59 ')

The following statement returns 4:select DateDiff (day, ' 1999/07/19 00:00 ', ' 1999/07/23 23:59 ')

The following statement returns 0:select DateDiff (month, ' 1999/07/19 ', ' 1999/07/23 ')

The following statement returns 1:select DateDiff (month, ' 1999/07/19 ', ' 1999/08/23 ')

Conditional statements:

SELECT * from MyDate where DateDiff (Day,datetime, ' 2016/05/06 14:30:00 ') =0

SQL Server Date Processing DateDiff

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.