[英]PHP - How to match today and yesterday date with database field
i have got data in following format in database 我在数据库中有以下格式的数据
2015-01-16 14:53:02
i am trying to get record matach with today and another for yesterday date. 我试图与今天和昨天的日期获得创纪录的成绩。
here is what i have tried 这是我尝试过的
//fetch today records
if ($button1pressed=="T1"){
$today = date('Y-m-d H:i:s');
$sqlquery="WHERE `datetime`="."'".$today."'";
}
//fetch yesterday records
if ($button1pressed=="T2"){
$yesterday = date('Y-m-d H:i:s',time() - 3600);
$sqlquery="WHERE `datetime`="."'".$yesterday."'";
}
and sql is something like this. 和SQL是这样的。
$sql="SELECT * FROM `me_olb1` ".$sqlquery ;
please need your help 请你帮忙
thanks 谢谢
That's not going to work, it will only give you results for the exact same hour, minute and second. 那是行不通的,它只会为您提供完全相同的小时,分钟和秒的结果。
You would need to extract the date from the datetime field. 您需要从datetime字段中提取日期。 For example:
例如:
for today: 今天:
$sqlquery = " WHERE DATE(`datetime`)=DATE(NOW()) ";
for yesterday: 对于昨天:
$sqlquery = " WHERE DATE(`datetime`)=DATE(DATE_SUB(NOW(), INTERVAL 1 DAY)) ";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.