Recently, I found out our SQL Server was storing events in UTC time. An application I was creating needed to get a list of events that happened on a certain certain day. Since our Central Standard Time was a little off, I had to come up with a fix for this.
I had a parameter in my .Net app called @evTime with the actual column named ‘eventTime’. I needed it to return rows for anything after midnight on that day up until midnight of the next day. So – here’s what I put in the WHERE clause of my stored procedure:
WHERE
--- blah blah blah
AND
(DATEADD(mi, DATEDIFF(mi, GETUTCDATE(), GETDATE()),
eventTime) >= @evTime
And
DATEADD(mi, DATEDIFF(mi, GETUTCDATE(), GETDATE()),eventTime)
< DATEADD(day, 1, @evTime))
All Things DotNet Discussed – Winforms/ASP.Net/SharePoint/WPF
Leave a reply
You must be logged in to post a comment.