I am using SQL Server 2014
Currently, I am using MSSQL function:
format(TODATETIMEOFFSET(("[dateColumn]",'-6:00'),'MM/dd/yyyy')
However, this will not apply Daylight savings.
How can i achieve it? Please help
I am using SQL Server 2014
Currently, I am using MSSQL function:
format(TODATETIMEOFFSET(("[dateColumn]",'-6:00'),'MM/dd/yyyy')
However, this will not apply Daylight savings.
How can i achieve it? Please help
This answer was provided before information was received that the OP was using SQL Server 2014 (which I have now added to their tags). I have left the answer here, however, as it will likely be helpful for future readers using a more recent version of SQL Server.
UTC -6 will always be UTC -6; it doesn't change for daylight savings and become UTC -5. Timezones like GMT (UTC+0) and EST (UTC-5) change to BST and EDT but then they also respectively become UTC +1 AND UTC -4. You're providing a literal number so the value will always be UTC -6.
What you are likely looking for is AT TIME ZONE
(AT TIME ZONE (Transact-SQL), which was introduced with SQL Server 2016. For example:
--Returns 2018-01-01 18:00:00 -06:00
SELECT CONVERT(datetime2(0), '2018-01-01T18:00:00') AT TIME ZONE 'Central Standard Time';
--Returns 2018-07-01 18:00:00 -05:00 (changes to -5, due to daylight saving)
SELECT CONVERT(datetime2(0), '2018-07-01T18:00:00') AT TIME ZONE 'Central Standard Time';