Summary of the time functions of SQL Server

Source: Internet
Author: User

1. Get the system Current time: Sysdatetime () and getdate () function. The difference is just not the same precision

2. DatePart (), DateDiff (), DateAdd ().

Example: SELECT DATEADD (year, DATEDIFF (year,-1, Sysdatetime ()),-1); Results: 2014-12-31 00:00:00.000, including system current time: 2014-08-18 19:20:58.6096869

Analysis: DATEDIFF (year,-1, Sysdatetime ()) results: 115. Because starting from 1990. 0--1990 years, -1--1989 years. DateDiff for the latter parameter minus one parameter, 114-( -1) =115.dateadd is added to the last two parameters: 115+ (-1) =114=2014 year, two functions are calculated in the first argument.

The SELECT DATEPART (weekday,getdate ()) result is 2, the current time is Monday, and 2 is the second day of the week.

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.