php根据时间查询sql的方法:1、通过strtotime将数据库时间转换成时间戳;2、通过“select * from `ecs_order_info` where add_time between...”语句选择并查询SQL数据即可。
本文操作环境:windows7系统、PHP7.1版、DELL G3电脑
php怎么根据时间查询sql?
下面是时间戳查询。如果数据库时间显示的是 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中完成
UNIX时间戳转换为日期用函数: date()
一般形式:date('Y-m-d H:i:s', 1156219870);
日期转换为UNIX时间戳用函数:strtotime()
一般形式:strtotime('2010-03-24 08:15:42');
在mysql中完成
这种方式在MySQL查询语句中转换,优点是不占用PHP解析器的解析时间,速度快,缺点是只能用在数据库查询中,有局限性。
UNIX时间戳转换为日期用函数: FROM_UNIXTIME()
一般形式:select FROM_UNIXTIME(1156219870);
日期转换为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”。
--结束END--
本文标题: php怎么根据时间查询sql
本文链接: https://www.lsjlt.com/news/486.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2023-03-24
2023-03-22
2023-03-06
2023-03-06
2023-02-18
2023-02-16
2023-02-15
2023-02-09
2023-02-03
2023-01-13
回答
回答
回答
回答
回答
回答
回答
回答
回答
0