Skip to main content
PHP Blog

Back to all posts

How to Search Between Dates Using MySQL?

Published on
3 min read
How to Search Between Dates Using MySQL? image

Best MySQL Tools to Buy in October 2025

1 High Performance MySQL

High Performance MySQL

  • AFFORDABLE PRICES: SAVE MONEY WITH QUALITY USED BOOKS!
  • ECO-FRIENDLY CHOICE: REDUCE WASTE BY BUYING PRE-LOVED BOOKS.
  • WELL-KEPT SELECTION: ENJOY A VARIETY OF GENRES IN GOOD CONDITION.
BUY & SAVE
$50.00
High Performance MySQL
2 Head First PHP & MySQL: A Brain-Friendly Guide

Head First PHP & MySQL: A Brain-Friendly Guide

BUY & SAVE
$17.43 $54.99
Save 68%
Head First PHP & MySQL: A Brain-Friendly Guide
3 Linux Server Hacks: 100 Industrial-Strength Tips and Tools

Linux Server Hacks: 100 Industrial-Strength Tips and Tools

  • AFFORDABLE PRICES ON QUALITY USED BOOKS!
  • ECO-FRIENDLY CHOICE-REDUCE WASTE WITH EVERY PURCHASE.
  • UNIQUE FINDS: DISCOVER RARE AND VINTAGE EDITIONS TODAY!
BUY & SAVE
$11.34 $24.95
Save 55%
Linux Server Hacks: 100 Industrial-Strength Tips and Tools
4 Murach's MySQL

Murach's MySQL

  • MASTER ESSENTIAL SQL STATEMENTS WITH EASY-TO-FOLLOW EXAMPLES.
  • BUILD AND MANAGE MYSQL DATABASES EFFICIENTLY AND EFFECTIVELY.
  • IDEAL FOR BEGINNERS WANTING TO ENHANCE THEIR CODING SKILLS FAST!
BUY & SAVE
$76.60
Murach's MySQL
5 Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)

Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)

BUY & SAVE
$30.15 $49.99
Save 40%
Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)
6 Build a real Search Engine: Engineering tools: HTML, CSS, JavaScript, PHP, MySQL

Build a real Search Engine: Engineering tools: HTML, CSS, JavaScript, PHP, MySQL

BUY & SAVE
$19.90
Build a real Search Engine: Engineering tools: HTML, CSS, JavaScript, PHP, MySQL
+
ONE MORE?

To search between dates using MySQL, you can use the BETWEEN operator in your SELECT query. Here's how you can do it:

  1. Start by writing your SELECT statement to retrieve the desired data from your table. For example: SELECT * FROM your_table
  2. Next, specify the column you want to search based on date range using the WHERE clause. For instance, if you have a column named "date" in your_table: WHERE date BETWEEN 'start_date' AND 'end_date' Replace 'start_date' with the starting date you want to search from, and 'end_date' with the end date of your desired search range.
  3. You can use any date format supported by MySQL like 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'. Make sure to use single quotes around the dates as MySQL expects them to be enclosed in quotes.
  4. Combining the above steps, a complete example query for searching between dates would look like: SELECT * FROM your_table WHERE date BETWEEN '2022-01-01' AND '2022-12-31' This query will fetch all the rows from your_table where the date column has a value between January 1, 2022, and December 31, 2022.
  5. Execute the query in your MySQL environment, and it will return the rows that match your date range.

Remember to adjust the table name, column name, and date range as per your specific requirements.

How to search for records within a specific day of the week in MySQL?

To search for records within a specific day of the week in MySQL, you can use the DAYOFWEEK() function along with the DATE or DATETIME field. The DAYOFWEEK() function returns the weekday index value (1 for Sunday, 2 for Monday, and so on).

Here's an example query to search for records on a specific day of the week:

SELECT * FROM your_table WHERE DAYOFWEEK(date_column) = 2; -- Searching for records on Monday (change the number for the desired day)

In this example, replace your_table with the actual name of your table and date_column with the name of the column that stores the date or datetime values you want to search.

You can adjust the = 2 part to search for other days of the week by changing the number accordingly.

How to search for records within a specific quarter of the year using MySQL?

To search for records within a specific quarter of the year using MySQL, you can use the functions YEAR() and QUARTER() along with the SQL BETWEEN operator. Here's an example:

SELECT * FROM your_table WHERE YEAR(date_column) = 2022 -- specify the year AND QUARTER(date_column) = 3; -- specify the quarter

In this example, replace your_table with the name of your table and date_column with the name of your date column. The YEAR() function extracts the year from the date, while the QUARTER() function extracts the quarter. The BETWEEN operator is used to filter records within the specified quarter (in this case, quarter 3).

What is the correct format for searching dates in the YYYY-MM-DD format in MySQL?

The correct format for searching dates in the YYYY-MM-DD format in MySQL is as follows:

SELECT * FROM table_name WHERE date_column = 'YYYY-MM-DD';

For example, if you have a table called "tbl_sales" with a column named "sale_date" and you want to search for sales made on January 1, 2022, the query would be:

SELECT * FROM tbl_sales WHERE sale_date = '2022-01-01';