Chris Whitfield
Posts: 0
Joined: Fri Jul 26, 2013 5:31 am

Filtering Events By Current Date

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!

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Filtering Events By Current Date

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.

Chris Whitfield
Posts: 0
Joined: Fri Jul 26, 2013 5:31 am

Filtering Events By Current Date

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 + '"}}}'

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Filtering Events By Current Date

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

Chris Whitfield
Posts: 0
Joined: Fri Jul 26, 2013 5:31 am

Filtering Events By Current Date

I get an incorrect query

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Filtering Events By Current Date

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

Chris Whitfield
Posts: 0
Joined: Fri Jul 26, 2013 5:31 am

Filtering Events By Current Date

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 + "}}'

Chris Whitfield
Posts: 0
Joined: Fri Jul 26, 2013 5:31 am

Filtering Events By Current Date

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

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Filtering Events By Current Date

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

Chris Whitfield
Posts: 0
Joined: Fri Jul 26, 2013 5:31 am

Filtering Events By Current Date

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

Return to “Issues”