search data between two dates in mongodb

146 views
Skip to first unread message

arpit bhatt

unread,
Jan 23, 2018, 4:05:17 PM1/23/18
to mongodb-user
Hi all,
how can I search data between two dates in mongo db? I am hitting following query 

db.student.find({
        createdTimestamp:{
            $gte: ISODate ('2018-01-01'),
            $lte: ISODate ('2018-01-10')
            }
})

but now the problem is I am not able to get data on the 2018-01-10 date.

Wan Bachtiar

unread,
Feb 7, 2018, 7:19:05 PM2/7/18
to mongodb-user

but now the problem is I am not able to get data on the 2018-01-10 date.

Hi Arpit,

What’s the value type stored in the field createdTimestamp?
If the values are in ISODate() then you should be able to retrieve documents where createdTimestamp are between those date range.

but now the problem is I am not able to get data on the 2018-01-10 date.

Could you provide example documents from the student collection containing createdTimestamp fields ?

See also MongoDB Date object

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages