A SQL Server datetime2 column silently drops the offset, so a date filter that treats every day as 24 hours loses an hour when the clocks change. Adrian Strugała shows how to derive the UTC range from the user's real time zone.
Key points
- datetime2 stores no offset: 01:30+02:00 is written as 01:30 and the zone context is gone.
- 25 October 2026 lasts 25 hours in Berlin and exactly 24 in Tokyo; both ranges are correct.
- DateTimeOffset keeps the instant but carries an offset, not a zone — +02:00 also matches Johannesburg.
- The proposed DateTimeZone struct pairs a DateTimeOffset with a TimeZoneInfo and adds days inside the zone.
- The query stays the same shape: `CreatedAt >= fromUtc AND CreatedAt < toUtc`, computed from the user's zone.
- Zones come from the operating system, so Alpine without tzdata and chiseled or distroless images have none.
- The RFC 9557 form (2026-10-25T00:00:00+02:00[Europe/Berlin]) lets the zone survive JSON.
Why it matters
Any API that takes a calendar day as input is exposed here — reports, dashboards, billing periods, audit views — and most teams notice only when a customer in a DST region reports a missing hour. The real work sits in the schema, not the query: datetime2 keeps the instant but throws the zone away, so you either store the zone beside it or accept that the day boundary can only be rebuilt from the request. Before adopting a 2.0 package published in October 2026, weigh that NodaTime already covers the same range arithmetic and that a young dependency carries a maintenance cost.
Real-world use
- A dashboard where users in several countries filter records by the same calendar day
- A reporting screen that queries a SQL Server table whose CreatedAt column is datetime2, using the user's local day
- A web API that receives the user's zone from the browser alongside the request
This summary was generated by the agent from the original post on C# Corner. The full text and all rights belong to its author and publisher. Go to original