I've following codes:
// 2017-Sep(09)-05 is selected in date picker
const dateToSearch = new Date(2017, 8 /*Month starts from zero*/, 5);
// context is oData context.
const customersOfThatSpecificDay = await context.customers.filter((c, d) => c.BirthDate == day, { day: dateToSearch }).toArray();
But it returns no data as it's comparing both date & time values for each customer. How can I compare them only by date?
Make sure that customer's BirthDate is saved in a column with DateTimeOffset type.
Even when there is no need to "time" in your scenario and you need "date" only, you've to use DateTimeOffset, because of time zones side effects.
// 2017-Sep(09)-05 is selected in date picker
const dateToSearch = new Date(2017, 8 /*Month starts from zero*/, 5, new Date().getHours(), new Date().getMinutes(), new Date().getSeconds()).toISOString();
// dateToSearch variable which is produced from your date picker must have two important things: 1- It should be in ISO format. 2- It's hour/minute/second should be the client's current date/time's hour/minute/second.
const customersOfThatSpecificDay = await context.customers.filter((c, d) => c.BirthDate.date() == d, { d: `date"${dateToSearch}"` }).toArray();
// This results into following odata query: (date(BirthDate) eq 'date"2017-09-05T08:06:05.000Z"')
c.BirthDate.date() means BirthDate without Time, even when it's saved in a column with DateTimeOffset type.
Notice that you've to submit current system time in your query (08:06:05.000Z in this sample) to server, and at server side, we determinate correct date based on time zone offset calculations. Without this, your solution is somehow incomplete, specially for globally distributed applications which have customers all across the world.
When we converted 'date"2017-09-05T08:06:05.000Z"' to something like 2017-09-05 without time, we're ready to compare two valid times.