I'm working on a blog and want to show my posts in eastern time zone. i figured that storing everything UTC would be the proper way. This creates a few challenges though:
I have to convert all times from UTC to Eastern. This is not a biggie but adds a lot of code.
And the "biggie" is that I use a short-date time to reference the posts by passing in a query, ala blogger. The problem is that there is no way to convert the short date time to the proper UTC date because I'm lacking the posted time info.
Hmm, any problem to just storing all dates in eastern time? This would certainly make it easier for the rest of the application but if I needed to change time zones everything would be stored wrong.
Update
@Jon, very much value your expertise, but I've decided storing UTC time in database is wrong. You may be able to convince me otherwise though!
So, let me give you the full skinny of it. I converted all the times to UTC, which required adding a lot more "syntax" in the declarative parts of the code.
What I'm coding is a blog, so I have 2 routes, a list route and a details route. The details route takes a short date and the name of the post which is assumes the combined to be unique. This is why it breaks down. I pass the short route in the query.
Depending on Time of Day, we can wrap around so that it is 29 or 30. So the short date must be correct because I don't have enough information in the query to determine how to convert the eastern time back to UTC.
I was storing a DatePosted "short date" with all times @ 12 AM for SQL purposes and a FirstModified long date for the time. So, I said, okay no problem, I'll just store the short date in eastern and then convert long date to eastern. No go because I can't make those query work.
So, I decided I went about this all wrong. The date should always be stored in eastern time (the time I want to use). And then if the user wants to change time zone (not a requirement), we just go through all the entries and change them.
Maybe, I'm thinking about this wrong but in my case there will only ever be eastern time zone used, so it is a waste of time either way.
Look forward to any input on this!
The key problems:
- I'm passing in a short date in the query. If this short date is in UTC then the date in the query could be off by 1. If I pass the short date as eastern then I will need a linq-to-sql syntax that can converted to SQL that will allow me to compare date times of different time zones.
Thanks again for all help!