ADO.NET Data Services and TimeZone

Silverlight Logo

There is a known problem with ADO.NET Data Services today that is important if you (or your server) lives in specific timezones.  The problem is associated with the way that the Silverlight Data Services Library constructs their URI for searches. 

The problem surfaces if you do a query that has a DateTime comparison in it. For example:

var qry = from o in ctx.Orders
          where o.OrderDate <= dt
          select o;

This query generates the following URI in the EST timezone in the US:

http://.../ProductService.svc/Orders()?$filter=OrderDate le datetime'2008-10-13T00:00:00-04:00'

This works great. The problem is that in other timezones (e.g. Bulgaria) where its forward of Greenwich Mean Time, so the UTC date is +03:00 like so:

http://.../ProductService.svc/Orders()?$filter=OrderDate le datetime'2008-10-13T00:00:00+03:00'

Because the "+" isn't URL Encoded, it becomes a space which makes the date incorrect.  For now you can convert the date to universal time but that's a hack at best:

var qry = from o in ctx.Orders
          where o.OrderDate <= DateTime.Today.ToUniversalTime()
          select o;

It works but its a hack.