Question

I am storing all dates to SQL Server as a UTC date time. I have Time Zone Id for each user stored in user profile as well.

Now when user requests data back, I want to display local time of user for each record using the Time Zone I have stored in profile for the particular user.

What is an easiest and optimized way (as I am processing heaps of records at the same time) to convert all dates and time to particular time zone on the fly while returning data? Either in SQL or in C# would be fine...

Very important question is, let's say there is a record created from Sydney when there was Day Light Saving "ON" and now Day Light Saving is "OFF". As the record was created when Day Light Saving was "ON", will it still convert the same time or will it return conversion as per current time zone status (which is Day Light Saving is "OFF")???

People only see those records which they had created from the particular

Was it helpful?

Solution

let's say there is a record created from Sydney when there was Day Light Saving "ON" and now Day Light Saving is "OFF". As the record was created when Day Light Saving was "ON", will it still convert the same time or will it return conversion as per current time zone status (which is Day Light Saving is "OFF")

The record contains an UTC date and time. This is going to fall into a DST ON or DST OFF period, deterministic. Is irrelevant whether the DST is in effect now. The opposite (storing local time, trying to extract UTC) is undetermined because of the overlap times when the DST changes (a small range of local times cannot be deterministically converted to UTC if they fall into the 60 mins that occurs twice when DST come into effect, assuming a 60 min DST).

As for the question: transform the date in your presentation layer. Use TimeZoneInfo.ConvertTimeFromUtc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top