1

I have following scenario:

USA: database & application server

Europe: client

The server reads a date time (e.g. 12:00) object from the database and send it to a client in Europe. The problem is now, the client displays this date time in the time zone of the client (e.g. 18:00), but we need the time in the database, independent of the time zone of the server. On the client we don't know from which time zone this value is.

So how can we achieve this?

Alfred Myers
  • 6,384
  • 1
  • 40
  • 68
Enyra
  • 17,542
  • 12
  • 35
  • 44
  • 1
    Related question: http://stackoverflow.com/questions/2532729/daylight-saving-time-and-timezone-best-practices – Oded Sep 17 '10 at 12:07

3 Answers3

1

your tags tell the answer.

use the TimeZone Class.

http://msdn.microsoft.com/en-us/library/system.timezone.touniversaltime.aspx

also: Creating a DateTime in a specific Time Zone in c# fx 3.5

So in your DB, times should be UTC. from there you can do anything what you want.

Community
  • 1
  • 1
Stefanvds
  • 5,868
  • 5
  • 48
  • 72
1

Can't you simply use DateTime.ToUniversalTime()?

http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx

Alternatively, if you don't want UTC, you can find out the timezone of your server and do something like:

DateTime dt;
TimeZoneInfo timezone_EST =
    TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");    
DateTime dt_EST = TimeZoneInfo.ConvertTime(dt, timezone_EST);
Dan Dumitru
  • 5,348
  • 1
  • 33
  • 43
  • The problem of this approach is, that i would have to iterate thru a dataset table with 10k rows to do this. – Enyra Sep 17 '10 at 12:20
0

If you're storing the DateTime data in SQL 2008, take a look at new datetimeoffset type which will store timezone information as well as the date and time themselves

Dav Evans
  • 4,031
  • 7
  • 41
  • 60
  • It doesn't store time zone information. It stores the offset from UTC at that moment in time. Those are *very* different things. Given a UTC instant and a time zone, I would know what the local time would be five minutes later. Given a UTC instant and an offset, I wouldn't. – Jon Skeet Sep 17 '10 at 12:10
  • unfortunatelly it is SQL 2005 which does not support this yet. – Enyra Sep 17 '10 at 12:18