DateTime Discrepancy

Adrian N 81 Reputation points
2021-08-27T08:15:27.073+00:00

Hey All

Just noticed an issue when inserting an object into my database with a DATE Column.
I have an object called a SalesOrder. In my app a sales order has an OrderDate Field which gets filled out automatically via DateTime.Today.

The issue is, when I run a breakpoint at the time of the object being inserted, the DateTime values are correct.

127063-datetime.png

But when I view the database, the field for order date is incorrect. It makes it the day before.
127054-db-row.png

Just wondering if this is caused by my SQL Server being located in US, and it does some sort of time conversion, and would this be fixed if I created my SQL Server and Database to somewhere closer.

Thanks in advanced!

Developer technologies | .NET | Xamarin
Azure SQL Database
{count} votes

Accepted answer
  1. KalyanChanumolu-MSFT 8,351 Reputation points
    2021-08-27T10:40:20.443+00:00

    @Adrian N Thank you for reaching out.

    It seems like the machine where the code is being debugged and the server where the database is hosted are in different time zones/locales.
    This should get corrected if you match the time zone settings on both machines.

    However, the recommended way of storing time stamps is to convert them to UTC first and then store in the database.
    When you retrieve the value, you convert them from UTC into the time zone of the client application.

    ----------

    If an answer is helpful, please "Accept answer" or "Up-Vote" which might help other community members reading this thread.


0 additional answers

Sort by: Most helpful

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.