title: Strapi.io filter data by date
body: <p>I'm trying to deep filter API response from Strapi backend from a custom controller with entityService, but seems like I'm doing something wrong.</p>
  <p>According to the documentation:
  <a href="https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/filtering-locale-publication.html#filtering" rel="nofollow noreferrer">Strapi filter data</a></p>
  <p>I can have multiple conditions there.</p>
  <ul>
  <li><strong>Strapi Version:</strong> 4.0.0</li>
  <li><strong>Operating System:</strong> macOS</li>
  <li><strong>Database:</strong> postgresql 14</li>
  <li><strong>Node Version:</strong> v14.17.6</li>
  <li><strong>NPM Version:</strong> 7.21.1</li>
  <li><strong>Yarn Version:</strong> 1.22.17</li>
  </ul>
  <p>My controller code:</p>
  <pre><code>    &quot;use strict&quot;;
  
  /**
   *  occasion controller
   */
  
  const { createCoreController } = require(&quot;@strapi/strapi&quot;).factories;
  const date = new Date().toLocaleString(&quot;en-US&quot;, {
    timeZone: &quot;America/Los_Angeles&quot;,
  });
  
  const dateClean = date.slice(0, 10).split(&quot;/&quot;);
  
  const dateISOCompat = [dateClean[2], dateClean[0], dateClean[1]].join(&quot;-&quot;);
  
  module.exports = createCoreController(
    &quot;api::occasion.occasion&quot;,
    ({ strapi }) =&gt; ({
      async find(ctx) {
        const { query } = ctx.params;
  
        const entity = await strapi.entityService.findMany(
          &quot;api::occasion.occasion&quot;,
          {
            ...query,
            populate: {
              image: true,
              button: true,
              category: true,
            },
            filters: {
              $and: [
                {
                  publishedAt: {
                    $notNull: true,
                  },
                  $and: [
                    {
                      category: {
                        startDate: {
                          $lt: dateISOCompat,
                        },
                      },
                      category: {
                        endDate: {
                          $gt: dateISOCompat,
                        },
                      },
                    },
                  ],
                },
              ],
            },
          }
        );
        return entity;
      },
    })
  );
  </code></pre>
  <p>Date comparison should work I think, my assumption that something wrong with the syntax of filter deep nested conditions.</p>
  <p>I still can get data from the API endpoint, but it didn't check for the date range...</p>
  <p>My response looks like this:</p>
  <pre><code>[
  {
      &quot;id&quot;: 1,
      &quot;title&quot;: &quot;Are you choosing a cake for the most important event in your life?&quot;,
      &quot;subtitle&quot;: &quot;&quot;,
      &quot;createdAt&quot;: &quot;2021-12-09T23:49:24.518Z&quot;,
      &quot;updatedAt&quot;: &quot;2021-12-30T20:59:28.264Z&quot;,
      &quot;publishedAt&quot;: &quot;2021-12-30T20:59:28.261Z&quot;,
      &quot;image&quot;: {
          &quot;id&quot;: 10,
          &quot;name&quot;: &quot;WeddingDate.jpg&quot;,
          &quot;alternativeText&quot;: &quot;WeddingDate.jpg&quot;,
          &quot;caption&quot;: &quot;WeddingDate.jpg&quot;,
          &quot;width&quot;: 2000,
          &quot;height&quot;: 1335,
          &quot;formats&quot;: {
              &quot;large&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/large_Wedding_Date_6c9d20762c.jpg&quot;,
                  &quot;hash&quot;: &quot;large_Wedding_Date_6c9d20762c&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;large_WeddingDate.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 125.61,
                  &quot;width&quot;: 1000,
                  &quot;height&quot;: 668
              },
              &quot;small&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/small_Wedding_Date_6c9d20762c.jpg&quot;,
                  &quot;hash&quot;: &quot;small_Wedding_Date_6c9d20762c&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;small_WeddingDate.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 43.24,
                  &quot;width&quot;: 500,
                  &quot;height&quot;: 334
              },
              &quot;medium&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/medium_Wedding_Date_6c9d20762c.jpg&quot;,
                  &quot;hash&quot;: &quot;medium_Wedding_Date_6c9d20762c&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;medium_WeddingDate.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 79.71,
                  &quot;width&quot;: 750,
                  &quot;height&quot;: 501
              },
              &quot;thumbnail&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/thumbnail_Wedding_Date_6c9d20762c.jpg&quot;,
                  &quot;hash&quot;: &quot;thumbnail_Wedding_Date_6c9d20762c&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;thumbnail_WeddingDate.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 12.95,
                  &quot;width&quot;: 234,
                  &quot;height&quot;: 156
              }
          },
          &quot;hash&quot;: &quot;Wedding_Date_6c9d20762c&quot;,
          &quot;ext&quot;: &quot;.jpg&quot;,
          &quot;mime&quot;: &quot;image/jpeg&quot;,
          &quot;size&quot;: 383.44,
          &quot;url&quot;: &quot;/uploads/Wedding_Date_6c9d20762c.jpg&quot;,
          &quot;previewUrl&quot;: null,
          &quot;provider&quot;: &quot;local&quot;,
          &quot;provider_metadata&quot;: null,
          &quot;createdAt&quot;: &quot;2021-12-09T19:34:37.053Z&quot;,
          &quot;updatedAt&quot;: &quot;2021-12-09T19:34:37.053Z&quot;
      },
      &quot;button&quot;: {
          &quot;id&quot;: 1,
          &quot;text&quot;: &quot;Order Now&quot;,
          &quot;buttonURL&quot;: &quot;/products/&quot;,
          &quot;style&quot;: &quot;Fill&quot;
      },
      &quot;category&quot;: {
          &quot;id&quot;: 1,
          &quot;name&quot;: &quot;Regular Occasions&quot;,
          &quot;startDate&quot;: &quot;2022-01-01&quot;,
          &quot;endDate&quot;: &quot;2024-12-31&quot;,
          &quot;createdAt&quot;: &quot;2021-12-09T23:49:59.083Z&quot;,
          &quot;updatedAt&quot;: &quot;2021-12-09T23:56:21.637Z&quot;,
          &quot;publishedAt&quot;: &quot;2021-12-09T23:55:11.891Z&quot;
      }
  },
  {
      &quot;id&quot;: 2,
      &quot;title&quot;: &quot;Make your birthday unforgettable and bright!&quot;,
      &quot;subtitle&quot;: &quot;&quot;,
      &quot;createdAt&quot;: &quot;2021-12-09T23:53:15.734Z&quot;,
      &quot;updatedAt&quot;: &quot;2021-12-22T22:06:15.962Z&quot;,
      &quot;publishedAt&quot;: &quot;2021-12-09T23:54:55.136Z&quot;,
      &quot;image&quot;: {
          &quot;id&quot;: 3,
          &quot;name&quot;: &quot;birthday_hero.jpg&quot;,
          &quot;alternativeText&quot;: &quot;birthday_hero.jpg&quot;,
          &quot;caption&quot;: &quot;birthday_hero.jpg&quot;,
          &quot;width&quot;: 1600,
          &quot;height&quot;: 1066,
          &quot;formats&quot;: {
              &quot;large&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/large_birthday_hero_af457271ec.jpg&quot;,
                  &quot;hash&quot;: &quot;large_birthday_hero_af457271ec&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;large_birthday_hero.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 56.99,
                  &quot;width&quot;: 1000,
                  &quot;height&quot;: 666
              },
              &quot;small&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/small_birthday_hero_af457271ec.jpg&quot;,
                  &quot;hash&quot;: &quot;small_birthday_hero_af457271ec&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;small_birthday_hero.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 20.62,
                  &quot;width&quot;: 500,
                  &quot;height&quot;: 333
              },
              &quot;medium&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/medium_birthday_hero_af457271ec.jpg&quot;,
                  &quot;hash&quot;: &quot;medium_birthday_hero_af457271ec&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;medium_birthday_hero.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 37.06,
                  &quot;width&quot;: 750,
                  &quot;height&quot;: 500
              },
              &quot;thumbnail&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/thumbnail_birthday_hero_af457271ec.jpg&quot;,
                  &quot;hash&quot;: &quot;thumbnail_birthday_hero_af457271ec&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;thumbnail_birthday_hero.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 6.63,
                  &quot;width&quot;: 234,
                  &quot;height&quot;: 156
              }
          },
          &quot;hash&quot;: &quot;birthday_hero_af457271ec&quot;,
          &quot;ext&quot;: &quot;.jpg&quot;,
          &quot;mime&quot;: &quot;image/jpeg&quot;,
          &quot;size&quot;: 108.92,
          &quot;url&quot;: &quot;/uploads/birthday_hero_af457271ec.jpg&quot;,
          &quot;previewUrl&quot;: null,
          &quot;provider&quot;: &quot;local&quot;,
          &quot;provider_metadata&quot;: null,
          &quot;createdAt&quot;: &quot;2021-12-09T19:34:35.479Z&quot;,
          &quot;updatedAt&quot;: &quot;2021-12-09T19:34:35.479Z&quot;
      },
      &quot;button&quot;: {
          &quot;id&quot;: 2,
          &quot;text&quot;: &quot;Order Now&quot;,
          &quot;buttonURL&quot;: &quot;/products/&quot;,
          &quot;style&quot;: &quot;Fill&quot;
      },
      &quot;category&quot;: {
          &quot;id&quot;: 1,
          &quot;name&quot;: &quot;Regular Occasions&quot;,
          &quot;startDate&quot;: &quot;2022-01-01&quot;,
          &quot;endDate&quot;: &quot;2024-12-31&quot;,
          &quot;createdAt&quot;: &quot;2021-12-09T23:49:59.083Z&quot;,
          &quot;updatedAt&quot;: &quot;2021-12-09T23:56:21.637Z&quot;,
          &quot;publishedAt&quot;: &quot;2021-12-09T23:55:11.891Z&quot;
      }
  },
  {
      &quot;id&quot;: 3,
      &quot;title&quot;: &quot;How to Express Words of Love on Father's Day?&quot;,
      &quot;subtitle&quot;: &quot;&quot;,
      &quot;createdAt&quot;: &quot;2021-12-10T00:01:49.722Z&quot;,
      &quot;updatedAt&quot;: &quot;2021-12-22T22:06:10.665Z&quot;,
      &quot;publishedAt&quot;: &quot;2021-12-10T00:13:18.089Z&quot;,
      &quot;image&quot;: {
          &quot;id&quot;: 15,
          &quot;name&quot;: &quot;FathersDay.jpg&quot;,
          &quot;alternativeText&quot;: &quot;FathersDay.jpg&quot;,
          &quot;caption&quot;: &quot;FathersDay.jpg&quot;,
          &quot;width&quot;: 1600,
          &quot;height&quot;: 664,
          &quot;formats&quot;: {
              &quot;large&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/large_Fathers_Day_7020aae6a3.jpg&quot;,
                  &quot;hash&quot;: &quot;large_Fathers_Day_7020aae6a3&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;large_FathersDay.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 22.33,
                  &quot;width&quot;: 1000,
                  &quot;height&quot;: 415
              },
              &quot;small&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/small_Fathers_Day_7020aae6a3.jpg&quot;,
                  &quot;hash&quot;: &quot;small_Fathers_Day_7020aae6a3&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;small_FathersDay.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 8.88,
                  &quot;width&quot;: 500,
                  &quot;height&quot;: 208
              },
              &quot;medium&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/medium_Fathers_Day_7020aae6a3.jpg&quot;,
                  &quot;hash&quot;: &quot;medium_Fathers_Day_7020aae6a3&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;medium_FathersDay.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 15.33,
                  &quot;width&quot;: 750,
                  &quot;height&quot;: 311
              },
              &quot;thumbnail&quot;: {
                  &quot;ext&quot;: &quot;.jpg&quot;,
                  &quot;url&quot;: &quot;/uploads/thumbnail_Fathers_Day_7020aae6a3.jpg&quot;,
                  &quot;hash&quot;: &quot;thumbnail_Fathers_Day_7020aae6a3&quot;,
                  &quot;mime&quot;: &quot;image/jpeg&quot;,
                  &quot;name&quot;: &quot;thumbnail_FathersDay.jpg&quot;,
                  &quot;path&quot;: null,
                  &quot;size&quot;: 3.45,
                  &quot;width&quot;: 245,
                  &quot;height&quot;: 102
              }
          },
          &quot;hash&quot;: &quot;Fathers_Day_7020aae6a3&quot;,
          &quot;ext&quot;: &quot;.jpg&quot;,
          &quot;mime&quot;: &quot;image/jpeg&quot;,
          &quot;size&quot;: 41.41,
          &quot;url&quot;: &quot;/uploads/Fathers_Day_7020aae6a3.jpg&quot;,
          &quot;previewUrl&quot;: null,
          &quot;provider&quot;: &quot;local&quot;,
          &quot;provider_metadata&quot;: null,
          &quot;createdAt&quot;: &quot;2021-12-10T00:13:06.981Z&quot;,
          &quot;updatedAt&quot;: &quot;2021-12-10T00:13:06.981Z&quot;
      },
      &quot;button&quot;: {
          &quot;id&quot;: 3,
          &quot;text&quot;: &quot;Order Now&quot;,
          &quot;buttonURL&quot;: &quot;/products/&quot;,
          &quot;style&quot;: &quot;Fill&quot;
      },
      &quot;category&quot;: {
          &quot;id&quot;: 3,
          &quot;name&quot;: &quot;Father's Day&quot;,
          &quot;startDate&quot;: &quot;2022-06-01&quot;,
          &quot;endDate&quot;: &quot;2022-06-19&quot;,
          &quot;createdAt&quot;: &quot;2021-12-10T00:03:52.295Z&quot;,
          &quot;updatedAt&quot;: &quot;2021-12-10T00:03:53.286Z&quot;,
          &quot;publishedAt&quot;: &quot;2021-12-10T00:03:53.283Z&quot;
      }
  }
  </code></pre>
  <p>.........</p>