1

I am using moment.js in Parse cloud code, I need to get an object by tomorrow's date. I am trying to use momentjs to get the day range.

    function getTommorowSongQuery() 
{
    var query = new Parse.Query("Song");  
    var tommorow = moment().add(1, 'days');
    var start = moment(tommorow).startOf('day');
    var end = moment(tommorow).endOf('day');

    console.log('start = ' +  start.toDate() + ' end = ' + end.toDate());
    query.greaterThanOrEqualTo("pushDate", start.toDate());
    query.lessThan("pushDate", end.toDate());

    return query;
}

The problem is that I get the current date (Today) while I expect to get tomorrow.

Any Idea what am I doing wrong.

shannoga
  • 19,649
  • 20
  • 104
  • 169
  • Maybe http://stackoverflow.com/questions/4413590/javascript-get-array-of-dates-between-2-dates/29145171#29145171 can help you? – gor181 Jul 22 '15 at 06:45
  • I see this a lot with momentJs and while I do not think it is your root issue, I do want to point it out. Your variable tomorrow is already a moment object so on your next two lines (for start and end) you do not need to put tomorrow into a new moment object like you are. You can simply just called, tomorrow.startOf('day') and tomorrow.endOf('day') – Jason H Jul 25 '15 at 15:33
  • I'm encountering this as well with `hours`. However, if I put it on a new object for example: `moment(today).add(1, 'days')` it returns the expected result for me. – JohnnyQ Aug 08 '16 at 16:57

0 Answers0