tags:

views:

1663

answers:

2

I've got a table in SQL Server 2005 that has a datetime column holding dates in UTC form. I want clients to call the a .NET server app and the server will return a DataTable with records to be bound client side to a DataGridView. ** On the client the dates should be displayed in local time **, clients will be in may regions of the world. Does anyone have any tips on achieving this? I could of course add a few lines to loop through and update the dates in the table before display but I can't help feeling there's got to be some snazzy funky way of doing this.

TA!!

A: 

DateTime.ToLocalTime Is what you're looking for.

Essentially, the fact that you're calling the method tells the DateTime object to add the current culture's offset from UTC and return the result. DateTime.ToUniversalTime does the opposite.

Neil Barnwell
A: 

First of all, make sure that the DATETIME values in your tables are stored as UTC values.

After that when you read them, the "client" application can convert them to local datetime (whatever that may be).

When inserting/updating stuff make sure you convert from local to utc before storing in the db.