I have a table within mysql with orders stored in it. I have figured out how to pull everything I need with my SELECT 开发者_StackOverflow社区statment. However, I was wondering, does anyone know how to grab orders only from today or even for the week using mysql? The table does contain an "order_date" field which is populated.
You can use this:
... WHERE order_date = CURDATE(); // today
... WHERE order_date BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE(); // in the week
Generally speaking (not knowing your schema):
SELECT * FROM orders WHERE order_date >= $start_date AND order_date <= $end_date
You need to define $start_date and $end_date
SELECT * FROM `orders` WHERE DATE(`order_date`) = DATE(NOW())
If the order_date is in datetime
EDIT
For a week
SELECT * FROM `orders` WHERE DATE(`order_date`) >= DATE_SUB(DATE(NOW()),INTERVAL 7 DAY)
精彩评论