php查詢時(shí)間段功能實(shí)現(xiàn):首先如果數(shù)據(jù)庫(kù)顯示時(shí)間是當(dāng)前時(shí)間,就不需要用strtotime 時(shí)間戳轉(zhuǎn)換函數(shù),然后直接聲明$timea,$timeb變量,獲取當(dāng)前時(shí)間字符串,最后聲明$sq2選擇add_time所在的時(shí)間段。
下面是時(shí)間戳查詢。如果數(shù)據(jù)庫(kù)時(shí)間顯示的是2011-04-05 那就不需要 用 strtotime 時(shí)間戳轉(zhuǎn)換函數(shù):
$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);
擴(kuò)展
在php中完成
1、unix時(shí)間戳轉(zhuǎn)換為日期用函數(shù): date()
一般形式:date('y-m-d h:i:s', 1156219870);
2、日期轉(zhuǎn)換為unix時(shí)間戳用函數(shù):strtotime()
一般形式:strtotime('2010-03-24 08:15:42');
在mysql中完成
這種方式在mysql查詢語(yǔ)句中轉(zhuǎn)換,優(yōu)點(diǎn)是不占用php解析器的解析時(shí)間,速度快,缺點(diǎn)是只能用在數(shù)據(jù)庫(kù)查詢中,有局限性。
1、unix時(shí)間戳轉(zhuǎn)換為日期用函數(shù): from_unixtime()
一般形式:select from_unixtime(1156219870);
2、日期轉(zhuǎn)換為unix時(shí)間戳用函數(shù): unix_timestamp()
一般形式:select unix_timestamp('2006-11-04 12:23:00′);
舉例:mysql查詢當(dāng)天的記錄數(shù):
$sql=”select * from message where date_format(from_unixtime(chattime),'%y-%m-%d') = date_format(now(),'%y-%m-%d') order by id desc”。更多學(xué)習(xí)資料:php實(shí)現(xiàn)手機(jī)歸屬地查詢視頻教程