我的日期输入日期为:20-10-2016
echo "<form method='post' action='rapor.php'>";
echo "<input type='date' name='pickdate' value=".date("Y-m-d")."> <input type='submit' value='Git'>";
echo "</form>";
$pickeddate = strtr($_POST['pickdate'], '/', '-');
echo date('Y-m-d', strtotime($pickeddate));
结果:2016-10-20
到目前为止一直很好......
我只需要显示我选择的行日期。
+------+-------------+---------------------+
| name | mail | dateandtime |
+------+-------------+---------------------+
| AAA | a@a.com | 2016-04-20 06:44:19 |
| BDC | b@c.com | 2016-10-21 06:44:19 |
| CDD | c@d.com | 2016-04-10 06:44:19 |
| EED | e@d.com | 2016-10-20 06:44:19 |
| SAS | a@s.com | 2016-04-10 06:44:19 |
+------+-------------+---------------------+
那是我的结果代码,但......
$result = mysql_query('SELECT * FROM dblist WHERE ('$pickeddate%') ');
为什么不工作?
答案 0 :(得分:0)
应该是
$newdate = date('Y-m-d', strtotime($pickeddate));
$result = mysql_query('SELECT * FROM dblist WHERE dateandtime LIKE "'.$newdate.'%" ');
答案 1 :(得分:0)
您的字段名称在哪里?
试试这个
$result = mysql_query('SELECT * FROM dblist WHERE dateandtime LIKE ('$pickeddate%') ');
答案 2 :(得分:0)
试试这个:
$pickeddate = date('Y-m-d', strtotime($_POST['pickdate']));
SELECT * FROM dblist WHERE date(dateandtime) LIKE '$pickeddate%';
答案 3 :(得分:0)
您必须使用as,
指定列名以执行条件$result = mysql_query('SELECT * FROM dblist WHERE dateandtime LIKE "'.$pickeddate.'%" ');
答案 4 :(得分:0)
您也可以尝试以下查询以获得预期结果
$newdate = date('Y-m-d', strtotime($pickeddate));
$result = mysql_query('SELECT * FROM dblist WHERE DATE(dateandtime) = "'.$newdate.'"');
这将比较确切的日期。