mysql query data based on time range

You can use MySQL's SELECT statement combined with the WHERE clause to query data based on a time range. Here are some common time range query examples:

  1. Query data for a specified date:
SELECT *
FROM table_name
WHERE date_column = '2021-10-15';

The above statement will return all rows with the date '2021-10-15' in the date_column column. You need to replace table_name with your table name and date_column with the date column name you want to query.

  1. Query data for a specified date range:
SELECT *
FROM table_name
WHERE date_column BETWEEN '2021-10-01' AND '2021-10-31';

The above statement will return all rows with dates between '2021-10-01' and '2021-10-31' in the date_column column. You need to replace table_name with your table name and date_column with the date column name you want to query.

  1. Query data for a specified time range:
SELECT *
FROM table_name
WHERE time_column BETWEEN '08:00:00' AND '17:00:00';

The above statement will return all rows with a time between '08:00:00' and '17:00:00' in thetime_column column. You need to replace table_name with your table name and time_column with the time column name you want to query.

  1. Query data for a specified date and time range:
SELECT *
FROM table_name
WHERE datetime_column BETWEEN '2021-10-01 08:00:00' AND '2021-10-31 17:00:00';

The above statement will return the date and time in thedatetime_column column between '2021-10-01 08:00:00' and '2021-10-31 17:00:00' all lines between. You need to replace table_name with your table name and datetime_column with the date and time column name you want to query.

Please choose the appropriate query statement and time format according to your specific needs.

Guess you like

Origin blog.csdn.net/qq_27487739/article/details/134592393
Recommended