SQL Server DATEDIFF () function

Source: Internet
Author: User

Server Date function

Definition and usage

The DATEDIFF () function returns the number of days between two dates.

Grammar
DATEDIFF (datepart,startdate,enddate)

The startdate and enddate parameters are valid date expressions.

The datepart parameter can be the following value:

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
Example 1

Use the following SELECT statement:

SELECT DATEDIFF (Day, ' 2008-12-29 ', ' 2008-12-30 ') as Diffdate

Results:

Diffdate
1
Example 2

Use the following SELECT statement:

SELECT DATEDIFF (Day, ' 2008-12-30 ', ' 2008-12-29 ') as Diffdate

Results:

Diffdate
-1

SQL Server Date function

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.