locked
Using a filter in ADO.NET DataServices to select by a date RRS feed

  • Question

  • Hi

     

    I am trying to use a filter in ADO.NET DataServices to select on a datetime field called date. I've drawn a blank with each of the following:

     

    date eq '29/10/2007' 

    error is:

    Operator 'eq' incompatible with operand types 'DateTime' and 'String' at position 5.

    The documentation - using ADO.NET Data Services ("Project Astoria") - says

    "If a date/time value needs to be specified, it can be written as a string (in quotes) and the system will attempt to convert it to a date/time if the other operand is a date/time"

     

    date eq cast('29/10/2007', 'datetime')

    error is:

    No applicable function found for 'cast' at position 8 with the specified arguments. The functions considered are: cast(System.Type); cast(System.Object, System.Type).

    I can't find any description of the use of cast.

     

    (day(date) eq 29) and (month(date) eq 10) and (year(date) eq 2007)

    no error but no results returned (and there should be)

     

    Any ideas would be gratefully received.

    Monday, January 14, 2008 5:48 PM

Answers

  • Hi,

     

    I struggled with this as well but what's working for me is something like;

     

    $filter=OrderDate eq '1996-07-04'

     

    I'm not sure whether this is sensitive to the locale that is set in the browser but I suspect that it's not.

     

    Thanks,

     

    Mike.

     

    Tuesday, January 15, 2008 4:26 PM

All replies

  • Hi,

     

    I struggled with this as well but what's working for me is something like;

     

    $filter=OrderDate eq '1996-07-04'

     

    I'm not sure whether this is sensitive to the locale that is set in the browser but I suspect that it's not.

     

    Thanks,

     

    Mike.

     

    Tuesday, January 15, 2008 4:26 PM
  • Thanks Mike

    That worked for case 1 (date eq '2007-10-29') which gets me up and running :-)

    Still interested to know why

    date eq cast('2007-10-29', System.DateTime)

    and

    date(day)eq 29 and date(month)eq 10 and date(year) eq 2007

    don't work
    Tuesday, January 15, 2008 5:48 PM
  • In the extensions preview, we're using the cast function only with entity types. The scenario was to allow downcasting so you can access properties that only exist in a subtype.

     

    I just posted a short overview of the available functions at http://blogs.msdn.com/marcelolr/archive/2008/01/15/arithmetic-and-built-in-functions-for-filter.aspx with a sample. The case I wrote isn't very interesting because I was using a default Northwind mapping, which doesn't have inheritance, but hopefully it explains what the intent is.

     

    Wednesday, January 16, 2008 1:26 AM
  • Thanks Marcello, that explains it.

    The last case was my error, so please ignore.


    Thursday, January 17, 2008 5:51 PM
  • Thanks Mike

    That worked for case 1 (date eq '2007-10-29') which gets me up and running :-)

    Still interested to know why

    date eq cast('2007-10-29', System.DateTime)

    and

    date(day)eq 29 and date(month)eq 10 and date(year) eq 2007

    don't work

     

    var query = context.Commoditiesses.AddQueryOption("$filter", "day(Date) eq 7 and month(Date) eq 6 and year(Date) eq 2011"

    );

    it,s work
    Monday, December 19, 2011 3:11 PM