EN
MySql - select rows with dates between
4
points
In this short article, we would like to show how my MySql select rows with a date between two dates.
SQL example:
SELECT client_id, creation_time
FROM clients
WHERE (creation_time BETWEEN '2020-06-01 00:00:00' AND '2020-06-01 23:59:59')
Note: this query will find all rows with
creation_time >= 2020-06-01 AND creation_time < 2020-06-01 23:59:59
. It means this query is not perfect if we want to find all day rows. The solution for the problem is query from second example where time information was removed.
Screenshot:
Using only dates example
By using specific dates only we are able to select all rows that are related to a specific days too.
SELECT client_id, creation_time
FROM clients
WHERE (creation_time BETWEEN '2020-06-01' AND '2020-06-02')
Note: this query will find all rows with
creation_time >= 2020-06-01 AND creation_time < 2020-06-02
.