Compare two dates with different formats with mongoDB query operators in React

162 Views Asked by At

I'm having trouble trying to filter by date in my query.

The problem is that from my CMS, the dates are coming in two different formats and I don't know why:

Mon Jan 02 2006 05:00:00 GMT-0300 (Argentina Standard Time)
2019-06-17T00:00:00-07:00

In my query, I'm trying to fetch the ones that are between two different dates, and both are in the second format shown (2019-06-17T00:00:00-07:00).

My filter consists in the following:

    const sets = await builder.getAll('open-dataset', {
      options: { noTargeting: true },
      omit: 'data.blocks',
      limit: 100,
      query: {
        data: {
          date: { $gte: newMinYear, $lte: newMaxYear },
          title: { $regex: search, $options: 'i' },
        }
      }
    });

pd: The title query is working

How can I accomplish this? because the filter is only working for those who has the same date format, and it's avoiding the ones with this one Mon Jan 02 2006 05:00:00 GMT-0300 (Argentina Standard Time).

Also, I can't add javascript to date, if not, I would have done something like new Date(date).

Can anyone help me here? thanks

0

There are 0 best solutions below