简体   繁体   English

获取MySQL中两个日期之间的差异天数

[英]Get the number of days of difference between two dates in MySQL

I'm trying to get the inactive users for the last 30 days. 我正在尝试吸引过去30天的不活跃用户。 by that i did this query: 通过这样做我做了这个查询:

SELECT * FROM users WHERE (30 - lastlogin) > 30

However I'm not getting any value, i wanted to see who are the users that did not loggin for the last 30 days. 但是我没有任何价值,我想看看谁是过去30天未登录的用户。 The date of the last login is like that in the database: 上次登录的日期类似于数据库中的日期:

DD/MM/YYYY
SELECT * 
FROM users 
WHERE DATEDIFF(NOW(), str_to_date(`lastlogin`, '%d/%m/%Y')) > 30

Hope this helps. 希望这可以帮助。

try use between constraction, for MySql must work follows: 尝试在约束之间使用,对于MySql必须工作如下:

select *
from users
where lastlogin between date_sub(now(), interval 30 day) and now();

See also: how to subtrack 30 days from the current datetime in mysql 另请参阅: 如何在mysql中从当前日期时间开始30天的子跟踪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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