This function will get the local time based on the time zone difference from UTC
IF OBJECT_ID(N'[GetLocalDate]') IS NOT NULL DROP FUNCTION [GetLocalDate] GO CREATE FUNCTION [dbo].[GetLocalDate] (@TimezoneDiffInHour FLOAT = - 5) RETURNS DATETIME AS BEGIN RETURN DATEADD(Hh, @TimezoneDiffInHour, GETUTCDATE()) END;
SELECT dbo.GetLocalDate(DEFAULT); -- or SELECT dbo.GetLocalDate(-5);
SELECT dbo.GetLocalDate(+1);
Last Updated on March 26, 2021