Languages
[Edit]
EN

MySql - select rows with dates between

4 points
Created by:
Marcin
2447

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.

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.