[英]Date comparison query php sql
I'm struggling to compare dates in an sql query on 2 counts - I've looked around at strtotime
/ date / from unixtime etc, but can't quite work it out. 我正在努力比较2个查询中的SQL查询中的日期-我已经在strtotime
/ date / unixtime等中四处查看,但是不能完全解决。
$currentday
is a date string in the format of 2013-12-29
$currentday
是日期字符串,格式为2013-12-29
Enddate is a 'date' type sql string - in the format 0000-00-00
(sometimes with dates and other times null
) Enddate是“日期”类型的sql字符串-格式为0000-00-00
(有时带有日期,其他时候为null
)
Here is the code: 这是代码:
///Find all regular payments ordered by amount descending
$check = mysql_query("
SELECT *
FROM
regular
WHERE
enddate >= ".$currentday." AND
userid = ".$varuserid."
ORDER BY amount desc
");
if($check === FALSE) {
die(mysql_error()); // TODO: better error handling
} else {
$regcheck = array(); //Assign details of valid regular payments for the user to an array
while($val=mysql_fetch_array($check)) {
//SHOULD BE LIMITED BY SQL QUERY - Don't understand why it isnt??
if (($val['enddate'] > $currentday) || (!$val['enddate'])) {
print $val['enddate'].'?'.$currentday.'<br/>';
//ERROR - NOT SURE WHY THIS SHOWS UP FROM THE SQL QUERY?
} else {
print 'err'.$val['enddate'].'?'.$currentday.'<br/>';
}
}
}
您必须引用字符串:
WHERE enddate >= '".$currentday."' AND ...
Unclear what the end goal is, but have adjusted your MySQL to accommodate 0000-00-00
and NULL
dates. 不清楚最终目标是什么,但是已经调整了MySQL以适应0000-00-00
和NULL
日期。
$check = mysql_query("
SELECT *
FROM
regular
WHERE
(enddate >= '" . $currentday . "' AND
enddate IS NOT NULL AND
enddate != '0000-00-00') AND
userid = ".$varuserid."
ORDER BY amount desc
");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.