0

I need to get the record from MongoDB based on the date using MongoDB. I am providing my collection below.

f_task:

{
        "_id": "5a13731f9402cc17f81ade10",
        "taskname": "task1",
        "description": "description",
        "timestamp": "2017-11-21 05:58:14",
        "created_by": "subhra",
        "taskid": "858fca9e2e153a61515c0372e079c521",
        "created_date": "21-11-2017"
    }

Here I need to fetch record as per created_date. Suppose user input is 20-11-2017 or 22-11-2017 then I need query to get the record if the given date is greater than or less than the "created_date" value.

halfer
  • 19,824
  • 17
  • 99
  • 186
satya
  • 3,508
  • 11
  • 50
  • 130
  • may be a [duplicate question](https://stackoverflow.com/questions/8835757/return-query-based-on-date). – oneturkmen Nov 21 '17 at 03:01
  • string date comparison is not going to work. For example 2-11-2017 is greater than 10-11-2017 in string comparison. So change the date from string to date type or you can save in iso date string(yyyy-mm-dd) which is supported by mongodb. – s7vr Jan 18 '18 at 14:21
  • Do you have to store the date as a string, or can you store it as a standard 'unix time' https://en.wikipedia.org/wiki/Unix_time? If you can store it as unix time, you can convert the user date to unix time, and do a simple $gt or $lt – DavidA May 28 '19 at 17:17

0 Answers0