Hello I have a record of calls made from different countries, I have the date and the country, the dates are adjusted to the time zone of each country, but I need to convert it to UTC, since I need to calculate the number of calls made in a month for all countries.
What they asked me to do is convert all the dates to UTC and take that date to do the calculation.
How can I do it? Any ideas?
I'm using this
PRINT DATEADD(hh, DATEDIFF(hh, GETDATE(), GETUTCDATE()), [fecha_llamada])
But that transforms it from the server's local time zone to UTC, but each date has a different time zone.
Try the same with the following function, but it is the same problem, it transforms me as if everything were from the same time zone.
CREATE FUNCTION dbo.fn_ConvertToDateTime (@Datetime BIGINT)
RETURNS DATETIME
AS
BEGIN
DECLARE @LocalTimeOffset BIGINT
,@AdjustedLocalDatetime BIGINT;
SET @LocalTimeOffset = DATEDIFF(second,GETDATE(),GETUTCDATE())
SET @AdjustedLocalDatetime = @Datetime - @LocalTimeOffset
RETURN (SELECT DATEADD(second,@AdjustedLocalDatetime, CAST('1970-01-01 00:00:00' AS datetime)))
END;
GO
Update 12/14/2018 # 1
Attached structure and example of the table
CREATE TABLE [TMP].[PortaCallDetails](
[ID] [int] NULL,
[charged_amount] [decimal](18, 3) NULL,
[charged_quantity] [varchar](50) NULL,
[country] [varchar](50) NULL,
[connect_time] [varchar](50) NULL,
[unix_connect_time] [varchar](50) NULL,
[disconnect_time] [varchar](50) NULL,
[unix_disconnect_time] [varchar](50) NULL
) ON [PRIMARY]
The data in the table are in text because they are taken from a file, this table is a temporary one from which the data for the definitive table is taken and transformed.
Update 12/14/2018 # 2
I need a function like this:
PRINT getUtcDate(@Date, @OffSet)
or with the country
PRINT getUtcDate(@Date, @Country)