0

I have SQL server table in that date field with IST time, I want to convert that datetime field into CST(Chicago) datetime. how can I write a function that can convert IST to CST and also manage the daylight saving.

Jack
  • 510
  • 3
  • 6
  • 22

1 Answers1

2
CREATE FUNCTION [DBO].[UDF_IST] (@FROM_DATE DATETIME)
RETURNS DATETIME
AS
BEGIN
    RETURN (
            SELECT CAST(SWITCHOFFSET(TODATETIMEOFFSET(GETDATE(), '+05:30'), '-06:00') AS DATETIME) AS [DATETIME]
            )
END

after that u need to check like this

SELECT dbo.[UDF_IST](@FROMDATE)
Chanukya
  • 5,833
  • 1
  • 22
  • 36