Reputation: 1911
I have a Silverlight application for agent evaluation. When doing the evaluation the DateTime is displayed correctly but after I subbmit an evaluation where I want to edit it later on I see that there is a -5 hour difference. The client is from Canada but the server seems to be somewhere else. I have read a little bit about it (have to use UTCDateTime) but it's a little hard to test because the application has to be deployed to be tested so that I don't want to be shooting in the dark.
Any help?
Edit: This is how I create the Evaluation
CurrentEvaluation = new Evaluation();
CurrentEvaluation.CreatedBy = UserID;
CurrentEvaluation.CreatedDate = DateTime.Now;
CurrentEvaluation.EvaluatorID = UserID;
CurrentEvaluation.EvaluationDate = DateTime.Now;
CurrentEvaluation.UserID = CurrentUser.UserID;
CurrentEvaluation.TenantID = CurrentTenant.TenantID;
Is it enough to say just CurrentEvaluation.EvaluationDate = DateTime.Now.ToUniversalTime();
and then convert it back to local time?
Upvotes: 0
Views: 241
Reputation: 93611
This may be overkill for your specific example, but when dealing with date/times that originate from different timezones (different to the server or also between clients), it is best to store them using the new DateTimeOffset structure introduced in Silverlight 3 along with the datetimeoffset field type of SQL Server 2008 R2.
This gives you the power to determine not just "universal time", but also to know what the times are relative to any given client.
When RIA services first came out it did not support the DateTimeOffset type (so we had to bodge a fix involving a DateTime and an int offset), but that was corrected in a later RIA service pack so you can use DateTimeOffsets as they were intended.
Upvotes: 1