Basically I'm converting local dates stored in the database into UTC. But I've read somewhere that daylight saving rules have changed in 2007. So does the Date.ToUniversalTime() function still work correctly. Basically the dates before 2007(when the new rules came into effect) would be converted correctly but the dates after that would be not. Am I right here? Or would .Net take care of the conversion internally i.e. depending upon the different daylight saving rules?
EDIT: Dates are stored in DB as local times. I am converting it into UTC. So a date such as '9 March 2005' should be converted using day light rules of 2005 instead of today's rules. The rules changed in the US in 2007. So the date is coming out wrong by one hour.
It will depend on which version of .NET you're using and possibly which version of Windows you're using. .NET 3.5 has the TimeZoneInfo class which includes historical changes etc - before then, the support was far more patchy, unfortunately.
It depends on how the information is stored in the database.
Hopefully, the data in the db contains the UTC offset, and if so, any changes to daylight saving rules will be irrelevant.
If the UTC offset isn't known then it is virtually impossible to know how to convert it to UTC. For example, if the time is stored as an integer with no metadata then the system would have to know when it was added to the db to be able to figure out the corresponding UTC timestamp.
I would expect ToUniversalTime()
to take that into account. Have you tried and checked the result with dates from before and after the DST change?
EDIT
If you know the timezone offset of all the dates in your DB, I definitively recommend you to convert them to UTC at the table level. You get rid of a whole lot of headaches that way. Converting to local time for display purposes is easier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With