Reputation: 188
Hi guys i have table in mysql
I need filter results where created_at and updated at difference between those timestamps 2 hours or less
I'am trying to use:
SELECT *
FROM `imoniu_r_padaliniai`
WHERE DATEDIFF(hour, created_at, updated_at) <= 2;
But i get syntax errot how achieve this?
Upvotes: 0
Views: 190
Reputation: 1270181
Just use direct comparisons:
where updated_at <= created_at + interval 2 hour
In MySQL and MariaDB, datediff()
only handles date differences. If you want arbitrary time differences, you need timestampdiff()
. However, I recommend using direct comparisons instead.
The three-argument form of datediff()
is the syntax in SQL Server (and a handful of other databases), not MySQL.
Upvotes: 1