title: How to create Daylight Savings time Start and End function in SQL Server
body: <p>I need to create a function in SQL server that returns daylight savings time start datetime and daylight savings time end datetime.</p>
  
  <p>I've come across a few examples on the web, however they all are using the 1st date of March and the 1st date of November and thats not technically correct.</p>
  
  <p>Daylight savings time begins at 2AM on the 2nd Sunday of March and ends on at 2AM in the first Sunday in November.</p>
  
  <p>I've started with the below code but I'm sure its wrong. Any assistance is appreciated! :)</p>
  
  <pre><code>DECLARE @DSTSTART DATETIME
  
  SELECT @DSTSTART = CASE WHEN 
  DATEPART(MONTH, SYSDATETIME()) = 3
  AND DATEPART(weekday, SYSDATETIME()) = 1
  AND DATEDIFF(week,dateadd(week, datediff(week, 0, dateadd(month, datediff(month, 0, SYSDATETIME()), 0)), 0), SYSDATETIME() - 1) = 2
  AND DATEPART(HOUR, SYSDATETIME()) = 2
  THEN SYSDATETIME()
  END
  RETURN (@DSTSTART)
  END
  GO
  </code></pre>