Momentjs:moment errors

Hi there - I’m having quite a perplexing issue that I can’t figure out.

I have a virgin project on 1.2.1 using the momentjs:moment package from Atmosphere.

When I call moment() in the browser console, I get a valid response, however, when I call moment() in code, then I get the following error in the console: Uncaught TypeError: m._d.getTime is not a function.

I’ve used moment before in previous projects with no problem, so I’m not sure why this isn’t working with a brand new project.

Any ideas?

How are you calling moment() in your code? Can you show us an example?

Sure. Here’s an example of the Method I tried on the server:

Template.hello.events({
‘click button’: function () {
var searchdate = moment().subtract(7, ‘day’)
Meteor.call(‘getPickups’,searchdate, function(err, data) {
if (err) console.log(err)
console.log(data)
})

}

});
}

Arguments to Meteor.call() need to be EJSON objects. Try passing the date in a different format, like unix offset:

var searchdate = moment().subtract(7, 'day').valueOf();
3 Likes

That didn’t work, but what did was:

var searchdate = moment().subtract(7, ‘day’).format(“YYYY-MM-DD”)

I don’t believe I’ve ever had to do it this way before, but at least it’s working now. Thanks!

1 Like

This will send searchdate as String. You can try to convert it to Javascript Date like this:

var searchdate = moment().subtract(7, 'day').toDate()
2 Likes

Thanks, somehow ended up here and your answer helped.

Thank you! took me hours to find this solution