select * from tablename where time>='2001-10-10 00:00:00' and time<='2002-10-11 23:59:59';
mysql 日期的字段是date型的,只要 date> '2001-10-10' and date< '2002-10-10' 如果不是的话,你就麻烦了,按照楼上字符串转为date型的,再比较.当然你的字符串以一定要是日期的指定格式的字符串才能转换成功.
关键是看的表的属性是date类型 还是datetime类型 如果是达特类型 select * from ### where date<'2002-10-10' AND date>'2001-10-10';如果是datetime类型 select * from ### where date<'2002-10-10 00:00:00' AND date>'2001-10-10 00:00:00';
如果你的时间字段是int类型... 只需.select * from table where SUBSTRING(FROM_UNIXTIME(时间字段名),1,10)>='2001-10-10'and SUBSTRING(FROM_UNIXTIME(时间字段名),1,10)<='2002-10-11';
$start_time="指定的时间"; $end_time=date("Y-m-d H:i:s A",(strtotime($define_time)+60*60*24*3)); // 3为想加的天数 // sql query; $sql="select * from table where time>$start_time and time<$end_time order by field";
php查询指定日期范围内的数据。(mysql数据库)
比如我想查询 2001-10-10 至 2002-10-11的所有数据。 select * from yourTaable where mydate between '2001-10-10' and '2002-10-11' [align=center]====思想重于技巧==== [/align]
如果不是的话,你就麻烦了,按照楼上字符串转为date型的,再比较.当然你的字符串以一定要是日期的指定格式的字符串才能转换成功.
只需.select * from table where SUBSTRING(FROM_UNIXTIME(时间字段名),1,10)>='2001-10-10'and SUBSTRING(FROM_UNIXTIME(时间字段名),1,10)<='2002-10-11';
$end_time=date("Y-m-d H:i:s A",(strtotime($define_time)+60*60*24*3)); // 3为想加的天数
// sql query;
$sql="select * from table where time>$start_time and time<$end_time order by field";
php查询指定日期范围内的数据。(mysql数据库)
比如我想查询 2001-10-10 至 2002-10-11的所有数据。 select * from yourTaable where mydate between '2001-10-10' and '2002-10-11'
[align=center]==== 思想重于技巧 ====
[/align]