Languages
[Edit]
EN

MySql - select rows with dates between

4 points
Created by:
Marcin
18820

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:

select rows with date-time between two dates - HeidiSQL with MySql
select rows with date-time between two dates - HeidiSQL with MySql

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.

MySQL - dates

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join