Molloch
Molloch

Reputation: 2381

OData Date Filtering from JS

I am using the DXTREME framework from Devexpress to connect a HTML mobile app to an OData source.

One of my tables in SQL Server, exposed through the OData service is a table with a date (not datetime) field in it. It is exposed through OData like this:

<d:TaskDate m:type="Edm.DateTime">2010-04-01T00:00:00</d:TaskDate>

I am trying to filter the data on this field through a calendar control, but when I try to filter the datasource on the JS side, I get no matches. This is because the date is passed to the OData service, I believe, in UTC format, so if I query for TaskDate = '10/JUL/2013', I believe the date is passed as "09/JUL/2013 14:00". If I filter on TaskDate > '10/JUL/2013' I get results back from after "09/JUL/2013 14:00" at any rate.

I have tried declaring a new date with no time part:

filterDate = new Date(2013, 6, 10)

but is still doesn't work, it still subtracts 10 formy time zone on the JS side.

What I want to do is to return a lists of Tasks valid on that particular date. How can I achieve this?

Upvotes: 1

Views: 1637

Answers (1)

Molloch
Molloch

Reputation: 2381

I think my problem was the confusion around the dxDateBox control returning just a date, and that date being changed when passed to my odata service.

I solved the issue by converting the date to UTC myself, but just using the Date parts from the control, (where filterDate came from the control):

var paramDate = new Date(Date.UTC(this.filterDate().getFullYear(), this.filterDate().getMonth(), this.filterDate().getDate()));
this.dataSource.filter(["TaskDate", "=", paramDate]);

This works nicely, but seems rather verbose.

Upvotes: 1

Related Questions