开发者

getdate tsql question

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜