getdate tsql question
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
- 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
dateadd(dd,datediff(dd,0, getDate()),0)
dateadd(hh,18 + (24 *datediff(dd,0, getDate())),0)
精彩评论