Search code examples
sqltimezoneutc

SQL - UTC Date Time Conversion


Transactions date time in our application are captured in UTC format. I need help in expiring the transactions based on local date time.

Example Scenario:

Points Expiration Date:

Local Time: 2019-07-17 13:55:22.317
UTC Time: 2019-07-17 08:25:22.317

How do I expire the points @2019-07-17 15:00:00.000 - As the expire engine (which runs based on UTC) is still not reached that time yet.

The expiration service runs in CST server and may not expire the points which are until UTC reaches that time. :(

What Am I missing here.?


Solution

  • SQL Server 2017 and up supports at time zone

    This allows you to evaluate a local date time to your target time zone

    select getdate() at time zone 'UTC'