需要有关 Unix 时间戳的帮助 [英] Need help on unix time stamp

查看:27
本文介绍了需要有关 Unix 时间戳的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我正在创建一个邮件程序系统,如果他们自 30 天以来未登录,则向我的非活动成员发送邮件以在他们的帐户中进行活动.

Basically, am creating a mailer system to send a mail to my inactive members to do activities in their account if they have not logged in since 30 days.

我以前的登录日期以 unixtimestamp 格式存储在我的数据库中,因此我编码如下.

My previous login date stores in my database in unixtimestamp hence I coded as below.

  select email from myusers where WHERE DATE_ADD(FROM_UNIXTIME(prelogin), INTERVAL 30 DAY) < CURDATE()";

但是此代码在 30 天后几乎每天都在发送连续邮件,因为我已将 cron 设置为每天运行一次.

But this code after 30 days it is sending continuos mails almost everyday as I have set cron to run once a day.

推荐答案

假设您只希望每 30 天发送一封电子邮件,并且仅当他们 30 天没有登录时,我怀疑最简单的解决方案是让表中的另一列称为last_email_sent_time.

Assuming you only want an email sent every 30 days, and only if they haven't logged in for 30 days, I suspect the easiest solution will be to have another column in your table called something like last_email_sent_time.

然后,仅在 预登录 该新列至少 30 天后才发送电子邮件.

Then, only send an email if it's been at least 30 days since both prelogin and that new column.

而且,当您发送电子邮件时,将该新列更新为当前日期,这样您就不会再打扰他们一个月左右.

And, when you send the email, update that new column to the current date so you won't bother them for another month or so.

另一方面,如果您只想在他们三十天未登录后发送一次电子邮件,这是类似的事情.

On the other hand, if you just want the email sent once after they haven't logged in for thirty days, it's a similar thing.

创建一个新列,指示电子邮件已发送,并且仅在该列为 false(或 N 或您想用来指示它的任何内容)时发送它.发送它将将该列设置为 true,登录会将其设置为 false(以及更改 prelogin).

Create a new column indicating the email has been sent and only send it if that column is false (or N or whatever you want to use to indicate it). Sending it will set that column to true, logging in will set it to false (as well as changing prelogin).

如果您不想添加额外的列(出于某种奇怪的原因),您可以在发送电子邮件时简单地更新 prelogin,尽管这不是我想要的很乐意提出建议,因为它丢失了可能在其他地方使用(或有用)的信息.

If you don't want to add extra columns (for some bizarre reason), you could simply update prelogin when you send the email, though that's not something I'm comfortable suggesting since it loses information that may be used (or useful) elsewhere.

这篇关于需要有关 Unix 时间戳的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆