I have a database table with column DATETIME called ‘entry_date’, such as…
ID entry_date
1 2012-10-13
2 2012-10-14
3 2012-10-15
4 2012-10-20
5 2012-10-20
6 2012-10-21
Whats the best way of echoing out the result for based on DATE in PHP/MYSQL, so i get just the results for this week so 2012-10-15 > 2012-10-21, but obviously i can’t just code that out because days change, everyday 🙂 so how would you do that in php so tomorrow the condition for this week would be 2012-10-16 > 2012-10-22
For today, use
For this month,
For this week
Above query is good for understanding. But not good for performance point of view. See the bellow modified one. Its far better.
Here DAYOFWEEK function returns an integer number starting from 1=Sunday. So your weeks will be counted as Saturday as starting date. If you want Monday add
+ Interval 2 daywith Interval.It can be also simplified to the following. But it does not support any day as first day of week. So its not portable to all culture.