Home > Database > Mysql Tutorial > sqlserver获取当前日期的最大时间值

sqlserver获取当前日期的最大时间值

WBOY
Release: 2016-06-07 18:02:46
Original
1331 people have browsed it

如果你有看到这篇,会看到Insus.NET在SQL Server2008使用最简单的方法取到午夜时间值。

那你也许会问及,怎样获取当前系统日期的最大时间值,如yyyy-MM-dd 23:59:59.997。

我们可以使用DATEADD函数,来实现,以当前日期的午夜时间值加一天,即得到第二天的午夜时间值,然后再减去3秒,即可以获取当前系统日期的最大时间值。
代码如下:
DECLARE @Date DATETIME = CURRENT_TIMESTAMP --当前系统日期时间

DECLARE @midnight DATETIME
SET @midnight = CAST(CAST(@Date AS DATE) AS DATETIME)
SELECT DATEADD(ms,-3,DATEADD(day,1,@midnight)) --2011-09-09 23:59:59.997
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template