繁体   English   中英

strtotime和datediff

[英]strtotime & datediff

我想请教我一些问题。

我当前的代码:

require_once 'MysqliDb.php';
$db = new MysqliDb('localhost', 'xy', 'xy', 'xy');
$users = $db->rawQuery('select * from police where datediff(skadenca,current_date())=30');

所以现在我选择当前日期为+ 30days的所有查询...但是问题是因为我想使用该脚本,所以也发送短信给birtdays,因为我需要以某种方式忽略current_date()中的year ...所以我想也许选择完整的日期,但strtotime并删除年份,所以我只需要日和月...

有什么快速解决方案吗?

抱歉,但我仍在学习php和sql,所以我的问题听起来可能很愚蠢?

感谢所有答案

您可以从日期中提取月份和日期(在当前日期加上30天之后),然后进行比较:

where date_format(skadenca, '%m%d') = 
      date_format(date_add(current_date(), interval 30 day), '%m%d')

但是请注意,如果生日是2月29日,则本年度可能没有匹配项。

在生日本身

您可以使用以下比较:

where date_format(skadenca, '%m%d') = date_format(current_date(), '%m%d')

要也匹配生日是2月29日且当前年份不是a年的一天,请扩展到以下内容:

where (date_format(skadenca, '%m%d') = date_format(current_date(), '%m%d')
    or date_format(skadenca, '%m%d') = '0229' and dayofyear(current_date()) = 60)

当生日在2月29日且当前年份不是a年时,它将与3月1日匹配。

在您的代码中,它应该看起来像这样-它使用字段rojstvo就像您在注释中提到的那样:

$users = $db->rawQuery("
    select * from police 
    where (date_format(rojstvo, '%m%d') = date_format(current_date(), '%m%d')
        or date_format(rojstvo, '%m%d') = '0229' and dayofyear(current_date()) = 60)
");

暂无
暂无

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

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