views:

629

answers:

1

How to pass in Date Time value here?

ObjectQuery<Item> _Query = ItemEntities.CreateQuery<Item>("Item");
_Query = _Query.Where("(it.StartDate >= 11/4/2009 5:06:08 PM)");

my sample code above does seem to work.

even with this

ObjectQuery<Item> _Query = ItemEntities.CreateQuery<Item>("Item");
_Query = _Query.Where("(it.StartDate >= \"11/4/2009 5:06:08 PM\")");

I got type cast error in EDM.

+1  A: 

The following should work:

ObjectQuery<Item> _Query = ItemEntities.CreateQuery<Item>("Item");
_Query = _Query.Where("(it.StartDate >= DATETIME'11/4/2009 17:06:08')");

See the documentation for more information on literals in ESQL queries.

pmarflee
still doesnt work, that gives me this error "The argument types 'Edm.DateTime' and 'Edm.String' are incompatible for this operation., near WHERE predicate, line 6, column 15."
Juvil John Soriano
@Juvil: I've updated the code snippet to include the DATETIME qualifier which is needed to distinguish date/time literals from string literals.
pmarflee
thanks, i see that's whats missing.
Juvil John Soriano