首先,你不应该在where子句中的操作符左侧使用mysql函数。这样mysql需要读取磁盘上的完整表来计算要比较的值,而不是优化查询速度和资源使用情况(IO,cpu)。
从你的问题和意见我明白,你正在查询数据库的行与$giorno_selected
代表的字符串有同一天。所以你需要找到特定日0:00到23:59之间,时间戳的所有行:
$giorno_timestamp_start = date_create_from_format('d-m-Y', $giorno_selected)->getTimestamp();
$giorno_timestamp_end = $giorno_timestamp_start + 86399; //add almost all seconds per day onto the start timestamp
$information="SELECT * FROM scheda_anagrafica WHERE time_inserted BETWEEN " . $giorno_timestamp_start. " AND ". $giorno_timestamp_end;
$result1 = mysql_query($information) or die (mysql_error());
while($row = mysql_fetch_array($result1)) {
echo $row['information1'];
}
这个作品,如果你time_inserted
列integer
型和持有unix_timestampds。 如果是datetime
型或timestamp
您需要修改本查询:
$information="SELECT * FROM scheda_anagrafica WHERE time_inserted BETWEEN FROM_UNIXTIME(" . $giorno_timestamp_start. ") AND FROM_UNIXTIME(". $giorno_timestamp_end .")";
你好,请你解释一下多一点? – nana
$ giorno_selcted – RomanKonz
的内容是肯定的,所以我在数据库中有一个字段,它是一个timstamp,当前日期即;让我们假设时间戳给我23-09-2012 12:23:45和日期变量给我23-09-2012,我需要检查时间戳和日期是否相等,但我需要在查询中这样做。 – Tao