Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP show data based on Yesterday and Today

Tags:

php

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.

like image 954
Hapshout DotCom Avatar asked Nov 23 '25 03:11

Hapshout DotCom


1 Answers

You can do it as below.

SELECT *
FROM tableName
WHERE date BETWEEN (CURDATE() - INTERVAL -1 DAY) AND CURDATE()
like image 177
Dipesh Parmar Avatar answered Nov 25 '25 18:11

Dipesh Parmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!