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.
Asked
Active
Viewed 765 times
0
-
please look at here: http://stackoverflow.com/questions/8038744/convert-datetime-column-from-utc-to-local-time-in-select-statement – Sandip - Frontend Developer Apr 20 '17 at 04:45
1 Answers
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