简体   繁体   English

strtotime和datediff

[英]strtotime & datediff

i would like to ask you for some help about my problem. 我想请教我一些问题。

my current code: 我当前的代码:

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

So now i select all queries where current date is +30days...but problem is because i want to use that script so send sms for birtdays too, si i need to somehow ignore year in current_date()...so i would like maybe to select full date, but strtotime and delete year, so i would need just day and month... 所以现在我选择当前日期为+ 30days的所有查询...但是问题是因为我想使用该脚本,所以也发送短信给birtdays,因为我需要以某种方式忽略current_date()中的year ...所以我想也许选择完整的日期,但strtotime并删除年份,所以我只需要日和月...

is there any quick solution for that? 有什么快速解决方案吗?

Sorry but i'm still learning about php and sql, so probably my question will sound stupid? 抱歉,但我仍在学习php和sql,所以我的问题听起来可能很愚蠢?

Thanks for all answers 感谢所有答案

You could extract the month and day from the dates (after adding 30 days to the current date), and compare that: 您可以从日期中提取月份和日期(在当前日期加上30天之后),然后进行比较:

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

Note however, that if the birthdate is on 29 February, there might not be a match in the current year. 但是请注意,如果生日是2月29日,则本年度可能没有匹配项。

On the birthday itself 在生日本身

You could use this comparison: 您可以使用以下比较:

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

To also match a day when the birthday is on 29 February, and the current year is not a leap year, extend to this: 要也匹配生日是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)

This will match 1 March when the birthday is on 29 February and the current year is not a leap year. 当生日在2月29日且当前年份不是a年时,它将与3月1日匹配。

In your code it should look like this -- this uses a field rojstvo like you mention in comments: 在您的代码中,它应该看起来像这样-它使用字段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