我在mySQL中完成了我的PHP脚本中的检查,在这里我选择了符合条件的条目,我需要对此进行增强:

outDate > ".sqltext(date("Y-m-d H:i:s", strtotime($data["inDate"])))."


outDate的日期必须晚于inDate,但以后的最大值应为2天。现在查询:

$sql = " SELECT id
         FROM inputs_outputs
         WHERE objectId=".sqltext($data["objectId"])."
         AND nfcTagId= ".sqltext($data["nfcTagId"])."
         AND nfcText = ".sqltext($data["nfcText"])."
         AND inDate < ".sqltext(date("Y-m-d H:i:s", strtotime($data["outDate"])))."
         AND inDate !='0000-00-00 00:00:00'
         AND outDate = '0000-00-00 00:00:00'
         ORDER BY inDate DESC LIMIT 1";

最佳答案

datediff返回两个日期之间的天数,因此您可以使用以下where子句确保outDate不大于inDate 2天

where outDate > inDate AND datediff(outDate,inDate) <= 2

10-08 11:08