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