我想知道在 PHP where targetDate < Date.Now - PHP 中的 HardCodedHours 中编写 where 语句的最佳方法是什么
问问题
3403 次
3 回答
22
如果您的意思是如何在 MySQL 查询中执行此操作:
SELECT * FROM table WHERE targetDate <= date_sub(now(), interval 1 hour);
于 2009-09-17T16:57:25.680 回答
5
这将从 DATETIME 列“targetDate”超过 12 小时的表“myTable”中提取“field1”。
$hardcodedHours = 12;
$sql = "SELECT field1 FROM myTable WHERE targetDate <= '" . date('Y-m-d H:i:s', strtotime("-$hardcodedHours hours")) . "'";
$result = mysql_query($sql);
于 2009-09-17T16:56:21.160 回答
0
$limitTime = time() - $nbHours * 3600;
$query = "SELECT ... WHERE TIMESTAMP(targetDate) < $limitTime;";
或类似的东西。
于 2009-09-17T16:57:43.690 回答