Get the count of records between two date, where dates value are in string with times

I am using the this query:
db.getCollection(“collectionName”).count({created_date:{ $gte:‘07-01-2023’,
$lte: ‘07-31-2023’}}), but its not returning right count.

Hello @Arif_Iqbal ,

Welcome to The MongoDB Community Forums! :wave:

Can you please share below details for me to test the query with respect to your documents?

  • Please share some sample documents
  • MongoDB Version being used
  • Expected Output Documents as per the sample documents

Regards,
Tarun

As I’m sure others will say as well, storing your dates in an illogical format will mean that doing anything meaningful with that data is non-trivial.

Convert them to proper dates, it’ll take up less storage, you’ll be able to query using them and it’ll be quicker.

2 Likes