简体   繁体   English

在mysql查询中使用纪元unix时间戳

[英]using an epoch unix timestamp in a mysql query

I'm trying to mark accounts inactive ( user_type = '1' ) which haven't signed in ( user_lastvisit ) within the last 90 days as inactive. 我试图将过去90天内未登录( user_lastvisit )的帐户标记为非活动( user_type = '1' )。

user_type tells phpbb if the account is 0 = active or 1 = inactive user_type告诉phpbb该帐户是0 =有效还是1 =不活跃

user_lastvisit is the last time the user signed into the phpbb board. user_lastvisit是用户最后一次登录phpbb板的时间。 It is stored in epoch time format. 它以纪元时间格式存储。

The problem: I can't figure out how to add 90 days to user_lastvisit (stored in epoch format) and see if it's less than the current time. 问题:我不知道如何向user_lastvisit(以纪元格式存储)添加90天,看看是否少于当前时间。

$result = mysql_query("UPDATE phpbb_users SET user_type = '1' WHERE DATE_ADD(FROM_UNIXTIME(user_lastvisit), INTERVAL 90 DAY) < NOW() AND user_type = '0'")
or die(mysql_error());

Update: I edited the query based on the suggestion below. 更新:我根据以下建议编辑了查询。

Take a look at FROM_UNIXTIME and DATE_ADD . 看一下FROM_UNIXTIMEDATE_ADD With those two functions you should be able to convert the timestamp to a datetime and then use it to add 90 Days. 使用这两个功能,您应该能够将时间戳转换为日期时间,然后使用它来添加90天。 Example: 例:

SELECT * FROM yourtable WHERE DATE_ADD(FROM_UNIXTIME(user_lastvisit), INTERVAL 90 DAY) > NOW()

Rather than working directly in the database which isn't recommended by the phpBB developers you can do this via your Admin Control Panel. 与其直接在phpBB开发人员不建议的数据库中工作,还可以通过管理控制面板执行此操作。

Log into the ACP and select the Users and groups tab. 登录到ACP,然后选择“ Users and groups选项卡。 At the bottom under User security select `Prune users' 在“ User security ”下的底部,选择“修剪用户”

In the Last active section set the drop down box to Before then enter the date from 90 days ago (as YYYY-MM-DD) 在“ Last active部分中,将下拉框设置为“ Before然后输入90天之前的日期(以YYYY-MM-DD表示)

Below this, make sure Delete pruned user posts is set to No , and Deactivate or delete is set to Deactivate 在此之下,确保将“ Delete pruned user posts设置为“ No ,并将“ Deactivate or delete设置为“ Deactivate

Hit the Submit button and this will deactivate all accounts not used within the last 90 days. 点击Submit按钮,这将停用过去90天内未使用的所有帐户。

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

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