我想根据记录日期是否在某个时间范围内(使用PDO)在MySQL数据库中返回记录。
时间范围:
$rangeStart = "17-Jul-18 04:45 pm";
$rangeEnd = "17-Jul-18 05:30 pm";
方法:
public function getForTokenIDAddressAndDateRange($token_id, $address, $rangeStart, $rangeEnd) {
$sql = "SELECT * FROM `{$this->table}` WHERE `token_id` = ? AND `address` = ? AND `date` <= ? AND `date` >= ?";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([$token_id, $address, strtotime($rangeStart), strtotime($rangeEnd)]);
}
记录中的示例“日期”值:
17-Jul-18 5:04 pm
如何使上述方法正常工作?我相信我需要将“日期”列值转换为时间戳,但不确定如何。谢谢!