您好,欢迎访问一九零五行业门户网

php中如何查询指定时间段的数据?

php中查询指定时间段数据的方法:使用strtotime时间戳转换函数,代码为【$timea = strtotime($_post['timea']);$sql = mysql_query($sq2);】。
php中查询指定时间段数据的方法:
下面是时间戳查询。如果数据库时间显示的是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编程从入门到精通
以上就是php中如何查询指定时间段的数据?的详细内容。
其它类似信息

推荐信息