Sqlserver obtains the maximum time of the current date.

Source: Internet
Author: User
If you see this article, you will see Insus. NET in SQLServer2008 using the simplest method to get the midnight time value.

If you see this article, you will see Insus. NET in SQL Server2008 using the simplest method to get the midnight time value.

You may ask how to obtain the maximum time value of the current system date, such as yyyy-MM-dd 23:59:59. 997.

We can use the DATEADD function to add a day to the midnight time value of the current date, that is, get the midnight time value of the next day, and then subtract 3 seconds, that is, you can obtain the maximum time value of the current system date.
The Code is as follows:
DECLARE @ Date DATETIME = CURRENT_TIMESTAMP -- current system Date and time

DECLARE @ midnight DATETIME
SET @ midnight = CAST (@ Date as date) as datetime)
Select dateadd (MS,-3, DATEADD (day, 1, @ midnight) -- 23:59:59. 997

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.