php查询时间段功能实现:首先如果数据库显示时间是当前时间,就不需要用strtotime 时间戳转换函数,然后直接声明$timea,$timeb变量,获取当前时间字符串,最后声明$sq2选择add_time所在的时间段。
下面是时间戳查询。如果数据库时间显示的是2011-04-05 那就不需要 用 strtotime 时间戳转换函数:
$timea = strtotime($_post['timea']);$timeb = strtotime($_post['timeb']);$sq2="select * from `ecs_order_info` where add_time between '$timea' and '$timeb' and `quanxian`='$dangqian' order by `order_id` desc limit 50";$sql = mysql_query($sq2);
扩展
在php中完成
1、unix时间戳转换为日期用函数: date()
一般形式:date('y-m-d h:i:s', 1156219870);
2、日期转换为unix时间戳用函数:strtotime()
一般形式:strtotime('2010-03-24 08:15:42');
在mysql中完成
这种方式在mysql查询语句中转换,优点是不占用php解析器的解析时间,速度快,缺点是只能用在数据库查询中,有局限性。
1、unix时间戳转换为日期用函数: from_unixtime()
一般形式:select from_unixtime(1156219870);
2、日期转换为unix时间戳用函数: unix_timestamp()
一般形式:select unix_timestamp('2006-11-04 12:23:00′);
举例:mysql查询当天的记录数:
$sql=”select * from message where date_format(from_unixtime(chattime),'%y-%m-%d') = date_format(now(),'%y-%m-%d') order by id desc”。更多学习资料:php实现手机归属地查询视频教程