我尝试在超过6个月的创建日期时搜索数据库中的所有用户。
我的数据库就像:
id username date_created
--------- ------------ ------------------
1 test 24.10.2016 09:33
2 user 09.08.2016 11:15
3 admin 08.08.2016 01:31
4 guest 11.01.2017 19:33
5 systems 01.09.2016 12:24
6 operator 02.09.2016 03:48
我的PHP:
$datum_6 = date("d.m.Y",strtotime("-6 month"));
$sql = "SELECT * FROM users WHERE date_created <= '$datum_6' ";
$result = $database->query($sql);
$suspend = array();
while ($row = $database->fetch_array($result)){
$suspend[] = $row['vpnuserreg'];
}
print_r ($suspend);
结果显示表中的所有用户(此表只是exmp。)
答案 0 :(得分:2)
您应该使用STR_TO_DATE
方法&amp;在那里条件
<强>更新强>
$datum_6 = date("Y-m-d",strtotime("-6 month"));
$sql = "select * from users where STR_TO_DATE(date_created, '%d.%m.%Y ') <= '$datum_6'";
答案 1 :(得分:0)
在比较之前将值转换为DATE:
$datum_6 = date("Y-m-d",strtotime("-6 month"));
$sql = "SELECT * FROM users WHERE DATE(date_created) <= '$datum_6' ";