Background
I have a scenario where I am calculating the difference between two dates. While the increment differences are spot on, the final calculation has introduced a 60 minute (1 hour) disparity.
After investigation and "hair pulling" episodes, I have identified that the DST transition in November is the cause for the 60 minute (1 hr) disparity.
Scenario
declare @sdate datetime = '2016-10-29 06:03:00.000PM'
declare @edate datetime = '2016-11-29 11:59:00.000PM'
select
DATEDIFF(HOUR, @sdate, @edate),
DATEDIFF(Minute, @sdate, @edate),
DATEDIFF(Second, @sdate, @edate)
Question
Ultimately, I need to simply return the number of seconds, or minutes, between the @sdate
and @edate
variables. I know there will be two times during the year, where the difference value will be off by 60 minutes (1 hour), plus or minus, and want to account for that known disparity within my sql statement.
How can i account for the DST adjustment within a set-based operation, if possible?
Currently, I am getting 44996
as the difference, but that is the un-adjusted time-change difference. I am looking for 45056
, which is the adjusted time-change difference.