Reputation: 53
I have an question about show data table based on date. In this case I want to show data based on today and yesterday.
Design table :
form_no | model_name | prod_status | date_added
Example data :
1 | acer | OK | 12-APR-2013
2 | acer | NG | 11-APR-2013
So if in table I just want the data will show once, because the model name is same.
Table view Like this
No | Model | Yesterday Status | Today Status
1 | acer | NG | OK
and here is my code :
$today = date("j-F-Y");
$yesterday = date("j-F-Y, time() - 60 * 60 * 24;");
$query = "SELECT model_name, prod_status, date_added FROM t_production_status WHERE date_added like '$today%'";
$result = mysql_query($query);
Now I'm done show data by today in table, now I want to display yesterday status to table view.
Upvotes: 3
Views: 209
Reputation: 27382
You can do it as below.
SELECT *
FROM tableName
WHERE date BETWEEN (CURDATE() - INTERVAL -1 DAY) AND CURDATE()
Upvotes: 5
Reputation: 157424
Use BETWEEN
in your query
$start_date = /* Yesterdays date */ ;
$end_date = /* Yesterdays date */ ;
$query = "SELECT * FROM table_name WHERE date_field BETWEEN $start_date AND $end_date";
Upvotes: 4