Realm-js: Filtering by Date without Time

Created on 11 Oct 2016  路  3Comments  路  Source: realm/realm-js

How to filter with specific date (ex. specific_date is Oct 09 2016 without time) in DB?
const result = realm.objects(type).filtered('DATE == $0', specific_date );

Mon Oct 10 2016 09:37:28 GMT+0800 (SGT)
Sun Oct 09 2016 09:37:28 GMT+0800 (SGT)
Sat Oct 08 2016 09:37:28 GMT+0800 (SGT)

Most helpful comment

You would want to compare against a range, matching dates at 12am of the day you want and 12am of the next day:

const result = realm.objects(type).filtered('DATE >= $0 && DATE < $1', specific_day, next_day);

All 3 comments

You would want to compare against a range, matching dates at 12am of the day you want and 12am of the next day:

const result = realm.objects(type).filtered('DATE >= $0 && DATE < $1', specific_day, next_day);

Thanks :)
Is realm possible to get strings such as "Mon" from date type?

Thanks @alazier

import { startOfDay, endOfDay } from 'date-fns';

const filterItems = taskLists.filtered('dueDate >= $0 && dueDate <= $1', startOfDay(new Date()), endOfDay(new Date()));
Was this page helpful?
0 / 5 - 0 ratings