The implementation method for the time value of midnight in SQL Server to get the current date _mssql2005

Source: Internet
Author: User
Tags datetime
Here is the infor syteline 8.02 's self-defined function:
Copy Code code as follows:

Midnightof
ALTER FUNCTION [dbo]. [Midnightof] (
@Date DATETIME
) RETURNS DATETIME
As
BEGIN
Return (DATEADD (datepart, @Date), DATEADD (month, DATEPART (month, @Date)-1), DATEADD (DATEPART ( Day, @Date)-1), ' 2000 '))
End

Here's the book.

The method provided on page 86th:
Copy Code code as follows:

SELECT DATEADD (Day,datediff (Day, ' 20010101 ', current_timestamp), ' 20010101 ');

The following is a insus.net method that can only be applied to SQL Server 2008 or later because there are date and time data types in this version.

Version 1:
Copy Code code as follows:

SELECT Cast ((CAST (CAST (Current_timestamp as DATE) as CHAR) + ' + ' 00:00:00.000 ') as DATETIME)


Version 2:
Copy Code code as follows:

SELECT cast (CAST (Current_timestamp as DATE) as DATETIME)
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.