How do I add Hours, mins, seconds to dateadd sql?

2019-04-30 04:48发布

问题:

I want to get an entire date

So today would be 7/7/2010 12:00:00 am to 7/7/2010 11:59:59 pm

So that should be the full 24 hours since 12:00:00 am would be the 8th then.

So I have this

select DATEADD(??, ??, DATEDIFF(dd, 0, GETUTCDATE()))

How do I make it add 23 hours 59mins and 59seconds to it?

回答1:

DECLARE @start DATETIME
DECLARE @end DATETIME

SET @start = DATEADD(dd, 0, DATEDIFF(dd, 0, GETUTCDATE()))
SET @end = DATEADD(dd, 1, DATEADD(ms, -3, @start))


回答2:

Try this:

DATEADD(second, -1, DATEADD(DAY, 1,"7/7/2010 12:00:00"))