It is not clear from your question, but I assume you have the values as a string. If so, then extract everything except the offset as a datetime
, also get the offset as a datetime
, then use the sign to calculate the final result (T-SQL, 2005):
DECLARE @withOffset varchar(30);
SET @withOffset = '2008-05-11T15:30:00+2:00';
PRINT N'Original: ' + CAST(@withOffset AS nvarchar);
DECLARE @dt datetime;
SET @dt = CONVERT(datetime, LEFT(@withOffset, 19), 126);
PRINT N'dt=' + CONVERT(nvarchar, @dt, 127);
DECLARE @ofs datetime;
SET @ofs = CONVERT(datetime, SUBSTRING(@withOffset, 21, LEN(@withOffset) - 21), 108);
PRINT N'ofs=' + CAST(@ofs AS nvarchar);
IF (SUBSTRING(@withOffset, 19, 1) = '+')
BEGIN
SET @dt = DATEADD(hour, DATEPART(hour, @ofs), @dt);
SET @dt = DATEADD(minute, DATEPART(minute, @ofs), @dt);
END
ELSE
BEGIN
SET @dt = DATEADD(hour, -DATEPART(hour, @ofs), @dt);
SET @dt = DATEADD(minute, -DATEPART(minute, @ofs), @dt);
END;
PRINT N'dt=' + CONVERT(nvarchar, @dt, 127);