Languages
[Edit]
EN

MySql - select rows with dates between

4 points
Created by:
maxsior322
347

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.

 

Alternative titles

  1. MySql / MariaDB - select rows with date between
  2. MySql / MariaDB - select rows for specific day
  3. MySql / MariaDB - select rows with dates between
  4. MySql - select rows with dates in range
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

MySQL

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