Select mysql query between date?

MysqlSelectDate

Mysql Problem Overview


How to select data from mysql table past date to current date? For example, Select data from 1 january 2009 until current date ??

My column "datetime" is in datetime date type. Please help, thanks

Edit:

If let say i want to get day per day data from 1 january 2009, how to write the query? Use count and between function?

Mysql Solutions


Solution 1 - Mysql

select * from *table_name* where *datetime_column* between '01/01/2009' and curdate()

or using >= and <= :

select * from *table_name* where *datetime_column* >= '01/01/2009' and *datetime_column* <= curdate()

Solution 2 - Mysql

All the above works, and here is another way if you just want to number of days/time back rather a entering date

select * from *table_name* where *datetime_column* BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY)  AND NOW() 

Solution 3 - Mysql

You can use now() like:

Select data from tablename where datetime >= "01-01-2009 00:00:00" and datetime <= now();

Solution 4 - Mysql

Late answer, but the accepted answer didn't work for me.
If you set both start and end dates manually (not using curdate()), make sure to specify the hours, minutes and seconds (2019-12-02 23:59:59) on the end date or you won't get any results from that day, i.e.:

This WILL include records from 2019-12-02:

SELECT *SOMEFIELDS* FROM *YOURTABLE* where *YOURDATEFIELD* between '2019-12-01' and '2019-12-02 23:59:59'

This WON'T include records from 2019-12-02:

SELECT *SOMEFIELDS* FROM *YOURTABLE* where *YOURDATEFIELD* between '2019-12-01' and '2019-12-02'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser176593View Question on Stackoverflow
Solution 1 - MysqlNoah HeldmanView Answer on Stackoverflow
Solution 2 - MysqlshakirthowView Answer on Stackoverflow
Solution 3 - MysqlKerriView Answer on Stackoverflow
Solution 4 - MysqlPedro LobitoView Answer on Stackoverflow