简体   繁体   中英

Search between two dates in mysql and php

Hi I want to search the items present in the table users. The code I wrote is

$fromdate = date("Y-m-d H:i:s", strtotime($_POST['fromdate']));
$todate = date("Y-m-d H:i:s", strtotime($_POST['todate']));

$s="SELECT * FROM logs WHERE dt BETWEEN $fromdate AND $todate  ORDER BY dt DESC ";
$x = mysql_query($s);

But the output is not showing. Please someone help me.

需要在'$fromdate''$todate'周围加上引号

$s="SELECT * FROM logs WHERE dt BETWEEN '$fromdate' AND '$todate' ORDER BY dt DESC ";
$fromdate = strtotime($_POST['fromdate']);
$todate = strtotime($_POST['todate']);

$query="SELECT * FROM logs WHERE UNIX_TIMESTAMP(dt) BETWEEN $fromdate AND $todate  ORDER BY dt DESC ";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM