0

I am fetching data according to date filter using node.js.

i have values stored in db as "February 12th 2016, 2:02:47 am"

When i am running find command

accounts.find({date:{$gte:'February 11th 2016, 59:59:59'}}).toArray(
        function(e, res) {
            if (e) callback(e)
            else callback(null, res)
        });

it returns the exact data i want. but when i runs the command

accounts.find({date:{$gte:'January 1st 2000, 59:59:59'}}).toArray(
        function(e, res) {
            if (e) callback(e)
            else callback(null, res)
        });

it returns nothing.

Please help me.

Thanks for your valuable time.

mscdex
  • 104,356
  • 15
  • 192
  • 153
Prem Tomar
  • 79
  • 10
  • 1
    Have you stored date as `string` literals ? You would never get the desired results, if you treat date as a string. – BatScream Feb 13 '16 at 07:27
  • as far as I know. (hope if I am wrong others can correct me).you will have to loop through each document and convert (if in shell) to date using the js new Date(). else it is just another string to mongodb. You can of course do that on the application level as well. – ibininja Feb 13 '16 at 08:22
  • better yet use ISODate(), – ibininja Feb 13 '16 at 08:23
  • Thanks guy's you helped me a lot :) – Prem Tomar Feb 13 '16 at 08:26
  • Follow answers from this [question](http://stackoverflow.com/questions/10942931/converting-string-to-date-in-mongodb) to get an idea of how you can convert the string formatted dates into date objects. – chridam Feb 13 '16 at 09:08

0 Answers0