Page 1 of 2

Filtering Events By Current Date

Posted: Thu Aug 15, 2013 5:14 am
by Chris Whitfield

Hello,

I have a collection of events and event start dates.

Is is possible to only request events that are occurring within the next 7 days?

I would imagine the app would need to figure out what day it is currently.

Thanks for your help!


Filtering Events By Current Date

Posted: Thu Aug 15, 2013 7:25 am
by Maryna Brodina

Hello! Please check this post https://getsatisfaction.com/apperyio/.... You just need to filter using your field with Date type, not the _createdAt field as suggested in that post.


Filtering Events By Current Date

Posted: Sat Aug 17, 2013 12:18 am
by Chris Whitfield

Hi Marina,

This is what I have so far for a where parameter on the page loading with the goal of listing events that are 7 days in the future from the current date. Its not working but maybe you can spot something i'm missing?

Thanks!

var d = new Date();
d.setDate(d.getDate() + 7);
var dateStr = d.toISOString();
return '{"EventStartDate":{"$gte":{"$date":"' + dateStr + '"}}}'


Filtering Events By Current Date

Posted: Sat Aug 17, 2013 2:02 am
by maxkatz

Take what's inside the return and run in the database console (open Query section). Do you get any data there?


Filtering Events By Current Date

Posted: Sat Aug 17, 2013 7:24 am
by Chris Whitfield

I get an incorrect query


Filtering Events By Current Date

Posted: Sat Aug 17, 2013 12:10 pm
by Igor

Hi,

Please try query string without "$date".

pre
code
{"EventStartDate":{"$lte":"+ dateStr +"}}
/code
/pre

You should first use simple query to ensure that everything works
pre
code
{"EventStartDate":{"$lte":"2013-08-24T20:42:05.465Z"}}
/code
/pre


Filtering Events By Current Date

Posted: Sat Aug 17, 2013 6:44 pm
by Chris Whitfield

Hi Igor,

This simple query works:

{"EventStartDate":{"$lte":"2013-08-24T20:42:05.465Z"}}

but trying the query string with $date doesn't work.

This is what i have in "where" on page load.

var d = new Date();
d.setDate(d.getDate() + 7);
var dateStr = d.toISOString();
return '{"EventStartDate":{"$lte":" + dateStr + "}}'


Filtering Events By Current Date

Posted: Sat Aug 17, 2013 6:45 pm
by Chris Whitfield

sorry, i meant trying the query string without $date...


Filtering Events By Current Date

Posted: Sun Aug 18, 2013 7:06 am
by Igor

Hi Chris,

It seems that in your "return" string some issue with quotation marks. Please copy/paste below code, I've tested this code, it works.
precode
var d = new Date();
d.setDate(d.getDate() + 7);
var dateStr = d.toISOString();
return '{"EventStartDate":{"$lte":"'+ dateStr +'"}}';
/code/pre


Filtering Events By Current Date

Posted: Mon Aug 19, 2013 12:41 am
by Chris Whitfield

Hey Igor,

It works! that great to see..

So i have a select menu with 3 options and their values:

Today: 0
Tomorrow: 1
Next 7 Days: 7

im storing the local variable as eventdaterange and im trying this code with no luck

var d = new Date();
d.setDate(d.getDate() + "' + localStorage.getItem("eventdaterange") + '");
var dateStr = d.toISOString();
return '{"EventStartDate":{"$lte":"'+ dateStr +'"}}';

Appreciate your help. I'm new to programming so its nice to see it coming together with your help.

Thanks