Handling Timezone Differences for ASP.NET Core Microservices and SQL Server

Shady Dorgham 25 Reputation points
2025-06-18T08:20:05.9633333+00:00

Hi Team,

We have several microservices built with ASP.NET Core running in container apps and SQL Server as the backend database. These services are currently hosted in the Central India Azure datacenter.

Our application primarily serves clients in Saudi Arabia, and handling time accurately is critical for our business processes. Currently, we're inserting datetime values into the database, but since the app is running in India, there are timezone differences affecting the calculations and display of time for our Saudi users.

Could you please guide us on the best practices for handling this scenario?

Specifically:

  1. I do not like to use utc date then convert it in the app that will require signficant change.
  2. Is there any Azure SQL Server or container apps feature that helps manage or configure timezones for this kind of scenario?

Looking forward to your guidance on how to handle this properly.

Thanks in advance!

Azure SQL Database
Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
686 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Khadeer Ali 5,990 Reputation points Microsoft External Staff Moderator
    2025-06-18T09:58:31.91+00:00

    @Shady Dorgham ,

    Thanks for reaching out.
    By default, Azure Container Apps run on UTC. If you’d like your application to use Saudi Arabia local time (UTC+3) without modifying your database logic or converting times in the app, you can configure the time zone directly in the container by setting the TZ environment variable.

    You can do this by adding the following environment variable to your Container App configuration:

    
    Name: TZ  
    Value: Asia/Riyadh
    

    This setting ensures your .NET Core application running inside the container uses the correct local time (Arab Standard Time), helping you maintain accurate datetime values in line with your business requirements in Saudi Arabia.

    Ref:

    https://luke.geek.nz/azure/change-timezone-azure-container-app/

    0 comments No comments

  2. Shady Dorgham 25 Reputation points
    2025-06-23T15:41:20.51+00:00

    Hi team ,

    That is fine will try and come back to you , but for azure sql server how to set time zone ?


  3. Saraswathi Devadula 5,570 Reputation points Microsoft External Staff Moderator
    2025-06-26T09:35:56.4633333+00:00

    Hello, Shady Dorgham

    Azure SQL Database does not support changing the default time zone, which is always set to UTC. However, you can convert the time to your desired time zone using the AT TIME ZONE function.

    Converts an inputdate to the corresponding datetimeoffset value in the target time zone. When inputdate is provided without offset information, the function applies the offset of the time zone assuming that inputdate is in the target time zone. If inputdate is provided as a datetimeoffset value, then AT TIME ZONE clause converts it into the target time zone using the time zone conversion rules.

    Refer: https://learn.microsoft.com/en-us/sql/t-sql/queries/at-time-zone-transact-sql?view=sql-server-ver17

    UTC:

    SELECT GETDATE() AT TIME ZONE 'UTC'
    

    Local Timezone:

    SELECT GETDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Singapore Standard Time' AS LocalTime;
    

    You can also make a User Defined Function (UDF) to convert UTC to your local time.

    User's image

    This can make it easier to use the conversion in multiple places in your database.

    CREATE FUNCTION dbo.ConvertToLocalTimeEightHour (@utcTime DATETIME)
    RETURNS DATETIME
    AS
    BEGIN
        RETURN DATEADD(HOUR, 8, @utcTime); -- Adjust 8 hours for UTC+8
    END;
    GO
    -- Usage
    SELECT dbo.ConvertToLocalTimeEightHour (GETDATE()) AS LocalTime;
    

    Hope this should help in your case.

    Let us know if you have any further concerns. I am happy to help you.


Your answer

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