# Wrong results for database query with date comparison

**URL:** <https://discourse.cakephp.org/t/wrong-results-for-database-query-with-date-comparison/9517>\
**Category:** Need Help\
**Created:** [July 9, 2021, 2:46am UTC](https://discourse.cakephp.org/t/wrong-results-for-database-query-with-date-comparison/9517 "2021-07-09T02:46:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpa](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@mpa](https://discourse.cakephp.org/u/mpa)\
**Post date:** [July 9, 2021, 2:46am UTC](https://discourse.cakephp.org/t/wrong-results-for-database-query-with-date-comparison/9517/1 "2021-07-09T02:46:42Z")

</div>

Hi

I have the following code for cakephp/cakephp": "~4.2.0:

```auto
$posts = $this->Posts->find()->where([
            'published IS NOT NULL',
            'user_id !=' => $this->_user_id,
            'published <=' => '2021-07-09 09:27:45'
        ])->order(['published' => 'DESC'])->limit(PAGINATE_LIMIT)->toArray();

```

which generates the following SQL

```auto
SELECT 
  Posts.id AS Posts__id, 
  Posts.user_id AS Posts__user_id, 
  Posts.created AS Posts__created, 
  Posts.modified AS Posts__modified, 
  Posts.updated AS Posts__updated, 
  Posts.published AS Posts__published, 
  Posts.summary AS Posts__summary, 
  Posts.text AS Posts__text 
FROM 
  posts Posts 
WHERE 
  (
    published IS NOT NULL 
    AND user_id != '60e6b7aeebd9a5.55375706' 
    AND published <= '2021-07-09 09:27:45'
  ) 
ORDER BY 
  published DESC 
LIMIT 
  5

```

But returns the wrongs results. Even after flipping the comparator.

If I copy and paste the SQL directly on MySQL, it returns the correct result.
