php中如何查詢指定時間段的資料

2021-12-26 02:03:38 字數 1361 閱讀 4756

1樓:娛樂小八卦啊

下面是時間戳查詢。如果資料庫時間顯示的是 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」。

2樓:莫路草根

儲存時間是int整形是嗎,這樣的話你先在php這邊把要查詢的時間段轉成時間戳再在資料庫查,這樣子:

$start_time = strtotime("2015-03-01 00:00");

$end_time = strtotime("2015-03-29 00:00");

select * from art where lasttime > $start_time and lasttime <= $end_time;

思路大致是這樣,你去寫寫看吧。

求一php** 就是查詢某一時間段資料歷史資料 資料庫mysql

mySQL中如何查詢指定的表中是否存在某個列

1 建立資料庫表,create table test users user id bigint,user name varchar 100 2 檢視系統檢視tables,在系統檢視中可以查到剛建的資料表,select from information schema.tables t where ta...

ecel該如何統計某個時間段內的出現次數

資料中 成功 和右邊的時間是在一個單元格還是兩個單元格?資料在分別在哪一列?最好截圖看一下,否則沒法幫你 資料不規copy範害死人的.這個打卡機實在設bai計的太du不理想了。參考圖示 根據數zhi據規律,統計早上的用 分析dao是7 8點用餐,如有其他時間酌情調整,下同 sumproduct le...

excel表如何統計時間段內的資料總和

1.e2公式 sumproduct year b 2 b 1000 年第 isoweeknum b 2 b 1000 周 d2 a 2 a 1000 下拉至70行 2.如果要自動提取周目數,d2公式 iferror year index b b,small if match isoweeknum b...