如何将 mysql 中的日期与当前日期进行比较并发送通知电子邮件
我的数据库条目有一个日期列( mySQL 日期类型)。我想每月将该日期与当前服务器日期以及该日期之前的 3 天进行比较,以自动向指定地址发送电子邮件。
I have database entrys that have a date column ( mySQL date type ). I want to compare that date with the current server date and with 3 days before that day, every month, to automatically send an email to a specified address.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以使用更简单的 MySQL TO_DAYS() 函数:
you can also use the simpler MySQL TO_DAYS() function :
您可以让 PHP 或 MySQL 为您做这些脏活,无论是脚本还是 SELECT 语句。
或者一个 SELECT 语句:
这个脚本以及一般的 PHP 的唯一问题是,只有在脚本运行时,它才会提前检查三天(或
$warning
中指定的值) 。如果你想让它继续检查,我建议你设置一个 CRON 作业。我不能保证其中任何一个都能工作,因为我还没有检查过它们。
希望这能给您一些关于此事的启发!
You can either make PHP or MySQL do the dirty work for you, either a script or a SELECT statement.
Or a SELECT statement:
The only problem with this script, and PHP in general, is that it will only check the three days (or the value stated in
$warning
) in advance only when the script is run. If you want it to keep checking I suggest you set up a CRON job.And I can't garantee that either of these will work as I haven't checked them.
Hope this gives you some inspiration on the matter!