不大明白需求,是要提取跟当前时间相差不到两个小时的记录吗,如果是这样 在sql语句中用UNIX_TIMESTAMP "select 要读取的字段 from 表 where UNIX_TIMESTAMP(dtime) < (UNIX_TIMESTAMP(now())+2*3600) and UNIX_TIMESTAMP(dtime) >UNIX_TIMESTAMP(now())" 或者 "select 要读取的字段 from 表 where UNIX_TIMESTAMP(dtime) < (".time()."+2*3600) and UNIX_TIMESTAMP(dtime) > '".time()."'"
蘇瑾熙
2026-02-26 10:26:32
应该这样写SQL语句:
$now=time(); $next=$now+2*3600; $SQL="select * from 表 where UNIX_TIMESTAMP(dtime) BETWEEN $now AND $next";