views:

39

answers:

1

Hi

Is there any way to prevent Silverlight/RIA Services from converting a datetime object on the wire?

Right now, I see datetimes set to 'Local' or 'Unspecified' being converted to the local time of the server when they are sent over the wire.

For example:

The client and server are both in UTC -04:00:00.

  • I use DateTime.Today (kind is either Local or Unspecified, it doesn't make a difference) on the Silverlight client. I see 23/08/2010 00:00:00.
  • I submit my changes and watch the data go over the wire. The field is expressed at 23/08/2010 00:00:00 (-04:00:00).

Great. Now I change my client to be in UTC +12:00:00

  • I use DateTime.Today on the client and now I see 24/08/2010 00:00:00.
  • HOWEVER - I submit my changes and watch the data again. Now I see 23/08/2010 08:00:00 (-04:00:00).

So it is apparent that the serializer is converting to the local time of the server, which I do not want. The value I want in the DB is 24/08/2010 00:00:00.

Using UTC is not a great option for this field as the database is part of our legacy application and the column contains invariant dates at this time. I don't want to start inserting UTC datetimes alongside the existing data.

Any ideas?

Thanks in advance

A: 

If I create the DateTime like this, it works:

new DateTime(DateTime.Now.Ticks, DateTimeKind.Unspecified).Date;
TheNextman