getdate tsql问题

时间:2010-12-01 18:51:24

标签: tsql

如何编写计算以下内容的TSQL:

  1. 当前日期和深夜,如2010-12-01 00:00:00.000
  2. 当前日期和下午6点,如2010-12-01 18:00:00.000
  3. 谢谢..

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:4)

您可以尝试以下内容

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