I was lazy and write an insert statement with DateTime.Now. It occur to me later i should have written DateTime.Now.ToUniversalTime(). This got me thinking, does ADO automatically convert dates into universal time? and restore it to local when i pull data out? Or do i need a write ToUniversalTime and ToLocalTime myself in every area of code? How should i manage time properly on my site?
Share
The
DateTimestructure contains theKindproperty that specifies if the value is a local time or an universal time (or unspecified).When you store the date in a database it’s only the date and time components that are stored. The
Kindcomponent is lost, so when you read theDateTimevalue from the database you can’t tell if it was a local or a universal time that was stored.I recommend that you store universal time in the database, and also put “UTC” in the field name to make it obvious what’s stored in the field, for example
CreatedUtcDate.