Santosh Sasupalli

Santosh Sasupalli

  • NA
  • 181
  • 25.2k

convert local time to utc time

Sep 8 2016 2:48 AM
USE [Gamyam]<br />GO<br />/****** Object: UserDefinedFunction [dbo].[convertutcdatetime] Script Date: 9/8/2016 12:06:05 PM ******/<br />SET ANSI_NULLS ON<br />GO<br />SET QUOTED_IDENTIFIER ON<br />GO<br /><br />ALTER FUNCTION [dbo].[convertutcdatetime]()<br />RETURNS datetime <br />AS <br />BEGIN<br /> DECLARE @ret datetime;<br /> declare @Diff nvarchar(20)<br /> select @Diff=TimeZone from Country <br /> SELECT @ret = convert(Datetime,switchoffset (CONVERT(datetimeoffset, GETUTCDATE()),@Diff));<br /> <br /> RETURN @ret;<br />END;<br /><br /><div>is there any mistake </div><div>&nbsp;</div><div>i got an error like this:</div><div>Msg 9812, Level 16, State 0, Line 1<br />The timezone provided to builtin function switchoffset is invalid.</div><div>&nbsp;please rectify me inthat @diff i put +530 i got out put.in my table value also +530 but it doesnot work helpme</div>

Answers (2)