Hi everyone - I am having a heck of a time trying to do something that should be very simple. I have created a form using autoform that collects two values - a title and a date. I now want to display these event on a page - ONLY if the event equals today.
I can get it to work for events before today and after today - but since minimongo for some reason does not support $eq - I cannot get it to work - what am I doing wrong???
Template.eventsView.helpers({
event: function() {
var isToday = new Date();
return Events.find({
date: isToday
});
}
});
I’ve tried not / not equals too but to no luck. Can Someone please help me out?
Not exactly, I want to view the Title of the event if the date that I set occurs today - so If i add an event called “Monday Morning Breakfast” and I give it a day of Monday morning (Im using a date picker and date object), I want it to appear on Monday.
I can return all events if it is before todays and after today but I cannot make evens thats only exists for today.
To me isSomething is a boolean, like Meteor.isClient for example. If someone else reads your code, or if yourself will read your code in a few months, I think it might be a good practice to rename your variable from isToday to today. Just my two cents…
Ohhh ok - since the datepicker is also passing the actual time with it - this is why its not working, because im saying get me all the documents that are that this very specific date / time stamp.
Is that the correct logic? Im only two weeks into meteor so your explanation is of help.
A datetime object is basically just a number - usually the amount of seconds since a particular date (like 1970-01-01 00:00:00). Thus, if you want everything from today, you need to pass in the datetime from this morning (i.e. it’s a discrete number which the Date class will then work with) and every datetime later than that is simply a larger number.
That’s about it, really.
Thus your original code indeed would have only gotten Events which had the exact same timestamp, down to the second.
This makes calculating time differentials easy. Everything else is slightly more work intensive.
It’s also why you don’t want to roll your own - because converting that number into an actual, human-readable timestamp is complicated. Leap years, leap seconds, timezones…