Skip to content

Filter is not working with date function #2437

Closed
@komdil

Description

@komdil

I am trying to use date function for filtering entities by todays date, but date function is not working

Assemblies affected

Microsoft.AspNetCore.OData 7.4.1

Reproduce steps

I have this entity:

new Student
            {
                Id = Guid.NewGuid(),
                Name = name,
                Score = score,
                Date = DateTime.Now,
            }

I am trying to get records which Date is equal to todays date. I executed some queries:
https://localhost:44383/odata/Student?$filter=Date +eq + now()
https://localhost:44383/odata/Student?$filter=Date +eq + date(now())
https://localhost:44383/odata/Student?$filter=date(Date) +eq + date(now())

Expected result

{
    "@odata.context": "https://localhost:44383/odata/$metadata#Student",
    "value": [
        {
            "Id": "b557bf76-8efd-4fb9-8fae-454d86876ed4",
            "Name": "Cody Allen",
            "Score": 130,
            "Date": "2021-03-19T00:00:00+05:00"
        }
    ]
}

Actual result



{
    "@odata.context": "https://localhost:44383/odata/$metadata#Student",
    "value": []
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions