开发者

getdate tsql question

开发者 https://www.devze.com 2023-01-28 14:55 出处:网络
How do I write TSQL that it calculates the following: the开发者_JS百科 current date and mid night such as 2010-12-01 00:00:00.000

How do I write TSQL that it calculates the following:

  1. the开发者_JS百科 current date and mid night such as 2010-12-01 00:00:00.000
  2. the current date and 6pm such as 2010-12-01 18:00:00.000

Thanks..


You can try something like the following

SELECT DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0) AS DateNoTime, 
    DATEADD(hh, 18, DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0)) AS DateNewTime


  1. dateadd(dd,datediff(dd,0, getDate()),0)
  2. dateadd(hh,18 + (24 *datediff(dd,0, getDate())),0)
0

精彩评论

暂无评论...
验证码 换一张
取 消