Skip to content

Instantly share code, notes, and snippets.

@kolexinfos
Created September 28, 2016 09:54
Show Gist options
  • Select an option

  • Save kolexinfos/77bbc895a697cc9bdcbc1604f6f343ee to your computer and use it in GitHub Desktop.

Select an option

Save kolexinfos/77bbc895a697cc9bdcbc1604f6f343ee to your computer and use it in GitHub Desktop.
var Verify = require('../models/verify');
var now = new Date();
now.setDate = (now.getHours() - 1)
Verify.find( //query today up to tonight
{"created_on": {"$gte": now }})
Throws an error of type mismatch, I also tested and see the that the $lt and $gte takes on Date types.
@bigmeech
Copy link
Copy Markdown

bigmeech commented Sep 28, 2016

function isMoreThanOneHourOld(datetime){
   var dateToCheck = moment(datetime);
   var now =  moment();
   return !dateToCheck.isAfter(now.subtract(1, 'hours'))
}

test with

isMoreThanOneHourOld(moment('2016-09-28 12:00:00')) //false

or

isMoreThanOneHourOld(moment('2016-09-28 10:00:00')) //true

@kolexinfos
Copy link
Copy Markdown
Author

Can you use it in the Mongoose Context like in my initial post, I know all this works but I need to check a dateTime field in a mongo collection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment