Languages
[Edit]
EN

MySql - select rows with dates between

4 points
Created by:
Marcin
15710

In this short article we would like to show how my MySql select rows with 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 inforamtion 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 with specific day 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.

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join