Question

Warning - TSQL newbie question ahead:

I've got a DateTimeOffset for, say, 2013-03-11 11:04:26.0000000 +00:00 and I need to create two new dates for the same day, one at 00:01 and another one at 23:59.

So far I've tried various things with DATETIMEOFFSETFROMPARTS and DATEPART but it seems way to awkward - is there a simple solution to snip off the hours/minutes/etc. and just use the day replacing the time with the two required ones?

Any hints appreciated.

Was it helpful?

Solution

Also you can try this option

DECLARE @date datetimeoffset = '2013-03-11 11:04:26.0000000 +00:00'
SELECT DATEADD(day, DATEDIFF(day, 0 , @date), '00:01'), 
       DATEADD(day, DATEDIFF(day, 0 , @date), '23:59') 

--Results:2013-03-11 00:01:00.000   2013-03-11 23:59:00.000

OTHER TIPS

Got it...

select @pkgDate = CONVERT (date, @pkgDate)

select DATEADD (minute, 1, @pkgDate)
select DATEADD(hour, 23, DATEADD (minute, 59, @pkgDate))

..better/more concise ways of doing it still appreciated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top