Azure cosmos db time difference in on-premises SQL server

Jakeer Shaik 106 Reputation points
2022-12-22T13:22:38.74+00:00

Team,

We are facing a weird issue while loading data from Azure cosmos db to on-premises sql server. Below is the background on the issue

we have two sources (D365 FO and Azure Cosmos db) and two targets (Dedicated SQL & On-premise sql). We load both sources data into both targets using azure synapse pipelines. we designed one dynamic pipeline to load all tables.

D365 - UTC Time Zone , Azure Cosmos db - UTC, Dedicated - UTC & on-premise sql - Mountain Time (UTC -7)

When we load the data from D365 to Dedicated and on-premises, it loads properly. The dates are loaded exactly what is there in source D365.
However, when we try to load from Azure Cosmos db to Dedicated, it works as expected. But, Azure cosmos to on-premises, date columns are reduced 7 hours.

We are not performing any transformation in both the loads. It is just a straight load (using copy activity).

It would be great if someone though some light on this. Why this is behaving like this and is there a solution for this.

Thanks,
Jakeer. Shaik

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ShaikMaheer-MSFT 38,631 Reputation points Microsoft Employee Moderator
    2022-12-26T06:51:48.15+00:00

    Hi @Jakeer Shaik ,

    Thank you for posting query in Microsoft Q&A Platform.

    When you get dates from different time zones and then try to store them in different time zones then system automatically add the offset and store it. In this case since you are getting UTC time zone data and storing it into Mountain Time (UTC-7) time zone column, system automatically reduces to 7 hours.

    For now, it looks its working good only. Any specific reason to not have offset? Between, what is the datatype of your column in onprem SQL?

    For some reason, If you want to take datatime value as it is even in Mountain time then Consider either of below approaches.

    you can consider having trigger running on that table to convert them using TODATETIMEOFFSET. Check this video which explains about Timezones and DATETIMEOFFSET datatype in SQL.

    OR

    You can have your column datatype as string if thats okay for you.

    Hope this helps.

    -----------------

    Please consider hitting Accept Answer button. Accepted Answers help community as well.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.