mysql select difference between two dates in days code example
Example 1: mysql date between two dates
-- With implicit CAST
SELECT * FROM my_table
WHERE my_date BETWEEN '2021-06-01 01:12:00' AND '2021-06-30 23:59:59';
-- is EQUIVALENT to
SELECT * FROM my_table
WHERE my_date >= '2021-06-01 01:12:00' AND my_col <= '2021-06-30 23:59:59';
Example 2: mysql datediff days
#Get date diff in days
select DATEDIFF('2020-04-13', '2020-04-20');#returns -7
select DATEDIFF('2020-04-20', '2020-04-13');#returns 7