Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 538
chobo2 Avatar asked Jul 07 '10 22:07

chobo2


2 Answers

DECLARE @start DATETIME
DECLARE @end DATETIME

SET @start = DATEADD(dd, 0, DATEDIFF(dd, 0, GETUTCDATE()))
SET @end = DATEADD(dd, 1, DATEADD(ms, -3, @start))
like image 127
LukeH Avatar answered Oct 10 '22 20:10

LukeH


Try this:

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

like image 40
Byron Whitlock Avatar answered Oct 10 '22 20:10

Byron Whitlock