How toMysql Query current week, last week, and last month...
Posted: Thu Jul 06, 2006 2:14 pm
Hi,
I can't figure out and find much information on making Mysql queries for the following:
Retrieve all rows for the date range of the current week. ex. Since it is Thursday today, I want to know what rows have been created since Sunday of this week.
Basically what I am trying to do is create a reports page for how many orders was made:
- today
- yesterday
- current week
- last week
- last month
Right now i have it like this and I'm not sure if this is correct or not.
$today = mysql_num_rows(mysql_query("SELECT * FROM Orders WHERE ODate = CURDATE()"));
$yesterday = mysql_num_rows(mysql_query("SELECT * FROM Orders WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= ODate"));
$this_week =
$last_week =
$last_month = mysql_num_rows(mysql_query("SELECT * FROM Orders WHERE DATE_SUB(CURDATE(),INTERVAL 1 MONTH) <= ODate"));
Any help would be great..thanks
I can't figure out and find much information on making Mysql queries for the following:
Retrieve all rows for the date range of the current week. ex. Since it is Thursday today, I want to know what rows have been created since Sunday of this week.
Basically what I am trying to do is create a reports page for how many orders was made:
- today
- yesterday
- current week
- last week
- last month
Right now i have it like this and I'm not sure if this is correct or not.
$today = mysql_num_rows(mysql_query("SELECT * FROM Orders WHERE ODate = CURDATE()"));
$yesterday = mysql_num_rows(mysql_query("SELECT * FROM Orders WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= ODate"));
$this_week =
$last_week =
$last_month = mysql_num_rows(mysql_query("SELECT * FROM Orders WHERE DATE_SUB(CURDATE(),INTERVAL 1 MONTH) <= ODate"));
Any help would be great..thanks