Database queries involving dates

--

Here is something you might not know — When querying databases, if you give it a date like ‘2022–06–01’, the computer sees it as ‘2022–06–01 00:00:00’.

So, if you want to return the records/ data before and on the date of 2022–06–01, below first option won’t work.

Option one:

≤ ‘2022–06–01’

This means ≤ ‘2022–06–01 00:00:00

Option two:

However, if you use:

≤::date ‘2022–06–01’

It actually means it will include the data on the date of June 1, 2022.

Ha ha! :)

Reference: Postgresql less than equal on dates — Stack Overflow

--

--

No responses yet