How to query data for a specified time period in php: use the strtotime timestamp conversion function, the code is [$timea = strtotime($_POST['timea']);$sql = mysql_query($sq2);] .
How to query data for a specified time period in php:
The following is a timestamp query. If the database time displays 2011-04-05, then there is no need to use the strtotime
timestamp conversion function:
$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);
Extended information
Complete in php
1. Use the function to convert UNIX timestamp to date: date()
General form:
date('Y-m-d H:i:s', 1156219870);
2. Use function to convert date to UNIX timestamp: strtotime()
General form:
strtotime('2010-03-24 08:15:42');
in
is completed in MySQL. This method is converted in the MySQL query statement. The advantage is that it does not take up the parsing time of the PHP parser and is fast. The disadvantage is that it can only be used in database queries and has limitations.
1. Function to convert UNIX timestamp to date: FROM_UNIXTIME()
General form:
select FROM_UNIXTIME(1156219870);
2. Convert date to UNIX timestamp Use function: UNIX_TIMESTAMP()
General form:
Select UNIX_TIMESTAMP('2006-11-04 12:23:00′);
Example: mysql query the number of records for the day:
$sql=”select * from message Where DATE_FORMAT(FROM_UNIXTIME(chattime),'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') order by id desc”。
Related learning recommendations : PHP programming from entry to proficiency
The above is the detailed content of How to query data for a specified time period in php?. For more information, please follow other related articles on the PHP Chinese website!