I have a datetime value. That datetime value may be in any timezone like \'Eastern Standard Time\' or \'India Standard Time\'. I want to convert that datetime value to UTC t
To convert to a time zone using the time zone name, you can do the following:
Find the number of minutes between the server timezone and your time zone-- Change to your time zone name
declare @TimezoneName varchar(max) = 'New Zealand Standard Time'
declare @timezoneOffset bigint = Datediff( MINUTE, getdate() at time zone @TimezoneName, getdate() )
Use SWITCHOFFSET to give you the datetime in your timezone.
eg when getdate() is '2020-04-16 04:47:25.640'
you get '2020-04-16 16:47:25.640 +12:00' (+12 for NZT)
select SWITCHOFFSET(getdate(), @timezoneOffset)
This should work in SQL Server 2016 and above.