关于我的问题,我想请你帮个忙。
我当前的代码:
require_once 'MysqliDb.php';
$db = new MysqliDb('localhost', 'xy', 'xy', 'xy');
$users = $db->rawQuery('select * from police where datediff(skadenca,current_date())=30');所以现在我选择所有查询,其中当前日期是+30days...but问题是因为我想使用该脚本,以便发送短信的生日也,si我需要以某种方式忽略年在current_date()...so我想可能要选择完整的日期,但strtotime和删除年,所以我只需要一天和一个月...
有什么快速的解决方案吗?
对不起,我还在学习php和sql,所以我的问题可能听起来很愚蠢?
感谢你所有的回答
发布于 2018-01-31 05:41:28
您可以从日期中提取月份和日期(在将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日且当前年份不是闰年的日期,请扩展到以下日期:
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日,并且当前年份不是闰年时,这将与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)
");https://stackoverflow.com/questions/48530481
复制相似问题