Select Data From Database Between Two Dates Best 5 Examples – How To Select Data Between Two Dates In MySQL?

Select Data From Database Between Two Dates : You have seen we have used ‘Y-m-d’ date format in our query. Select Data From Database Between Two Dates i can mysql query between dates with the help of BETWEEN mysql statement with examples also you can read select data between two dates in mysql.

Example 1 : Use BETWEEN….AND…. Comparison Operator

`product_date` BETWEEN '2022-04-05' AND '2022-04-10' // Retrun data including 05-04-2022 to 10-04-2022
 
`product_date` BETWEEN '2022-04-05' AND CURDATE() // Retrun data including 05-04-2022 to Current Date

SELECT * FROM `product` WHERE `product_date` BETWEEN '2022-04-15' AND '2022-04-30'

Example 2 Use > AND < Comparison Operator

SELECT * FROM `product` WHERE `product_date` >= '2022-04-15' AND `product_date` <= '2022-04-30'

Examples – Select Data From Database Between Two Dates

Example 1 Select Records Between Two Years

SELECT * FROM `product` WHERE YEAR(product_date) BETWEEN '2021' AND '2022'

Example 2 Select Records Between Two Months

SELECT * FROM `product` WHERE MONTH(product_date) BETWEEN '05' AND '06'

Example 3 Select All Records Between Two Months of Specific Year

SELECT * FROM `product` WHERE MONTH(product_date) BETWEEN '05' AND '06' AND YEAR(product_date) = '2022'

Example 4 Select All Records of Specific Month

SELECT * FROM `product` WHERE MONTH(product_date) = '05'

Free Live Chat for Any Issue

Example 5 Select All Records of Current Month

SELECT * FROM `product` WHERE MONTH(product_date) = MONTH(CURDATE())

Example 6 Select All Records of Specific Year

SELECT * FROM `product` WHERE YEAR(product_date) = '2022'

Example 7 Select All Records of Current Year

SELECT * FROM `product` WHERE YEAR(product_date) = YEAR(CURDATE())

Example 8 Select All Records of Specific Month & Specific Year

SELECT * FROM `product` WHERE MONTH(product_date) = '05' AND YEAR(product_date) = '2022'

I hope you get an idea about Select Data From Database Between Two Dates.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Rate this post