views:

51

answers:

1

Hey!

I've published a web application to a server in the USA. The app is actually for swedes (people in Sweden) and I am looking for the best way to hadle the time difference.

There's a +7 hour difference.

Should I store the DateTime.Now in DB as it is, or should I use DateDiff to change the time before creating each record?

What's the best practice here? What to store in the database? Should the date only be differed when presenting it?

Best practices, please!

+6  A: 

Hi,

I usualy store the DateTime.UtcNow which is the utc time. So when it's 13.00 in UTC, it's 14.00 in Sweden and 7.00 in the USA, you store the UTC time (13.00) and you can always format the datetime with a New CultureInfo("sv-SE") to the local time in Sweden, the USA etc.

Michel

Michel
+1. Also, you might want to put "UTC" somewhere in the database field so that it's clear what kind of time that is stored. Another neat thing about UTC time is that it's linear across daylight savings time changes.
Guffa
Ok, great! But when printing the date and time, I must do the Date.AddHour(1) or is there any better way?
Mickel
Read above carefully: "and you can always format the datetime with a New CultureInfo("sv-SE") to the local time in Sweden"
dario-g
Yep, if variable dt is the UTC datetime, you get the Sweden datetime with this: DateTime swedenDateTime = Convert.ToDateTime(dt, new CultureInfo("sv-SE"));
Michel
Oh, thanks for explaining Michel! :)
Mickel