0

I have a C# WASM Blazor Server-Side app.

When a user is selecting 29th March 2022 it's going into the database as 28th March 2022 at 23:00 hours.

Pushing it back 1 hour and into the previous day.

When i debug in VS with a local browser and step through the code this doesn't happen.

I feels like the client-side of the app is adjusting the time for live users.

We want everything in UTC but i cannot work out where i need to fix this.

The field in the DTO being sent the the business logic data is:

public DateTime? LatestPickupDate { get; set; }

and it's a datetime2(7) in the SQL Database

Can anyone offer any advice please?

Thanks

Trevor Daniel
  • 3,785
  • 12
  • 53
  • 89
  • 1
    If you're working across time zones, it's a good idea to switch to using `DataTimeOffset` which takes the pain out of dealing with times/dates - see this answer which explains all - https://stackoverflow.com/questions/4331189/datetime-vs-datetimeoffset?msclkid=40352a14aea211ec8cf17bcaa5e3c210. Most SQL Servers has the equivalent field. – MrC aka Shaun Curtis Mar 28 '22 at 14:22

2 Answers2

0

You have to deal by yourself about the client timezone

some explanation here : https://www.meziantou.net/convert-datetime-to-user-s-time-zone-with-server-side-blazor.htm

keep in mind :

  • save the date in your database in UTC (retrieve the field as UTC like the example above)
  • when you render existing date from database at your user, do the inverse operation (adjust the utc date datetime to local with the client TimezoneOffset
JulienG
  • 158
  • 1
  • 14
0

This turned out to be a problem with Safari. The date comes across correctly when the user is on Chrome

Trevor Daniel
  • 3,785
  • 12
  • 53
  • 89