Why do we prefer an universal UTC time on a website rather than a local time?
If everyone is located in same time zone then we will have a same time stamp. However, it is not possible. Most time users are from all over the world then time consistency would be a problem for a website. This confusing situation will be getting worse when we are saving a local date time input from frontend into a Database. What will be the solution? The answer is to save all data with an universal UTC time stamp. In order to do that, we need to convert local time (that could be an user input on a website frontend) to UTC (Coordinated Universal Time) in SQL.
Converting Local Time to UTC - Sample Codes:
DECLARE @LocalDateTime datetime
DECLARE @TimeZoneOffset INT
SET @LocalDateTime = @input_datetime_from_frontend -- This is an input date time from .net frontend.
SET @TimeZoneOffset = DATEDIFF(MI, SYSDATETIME(),SYSUTCDATETIME())
SELECT DATEADD(MI,@TimeZoneOffset, @LocalDateTime)
--Problem is resolved.