[英]mysql date interval, php date interval
I have students table and they must pay every month, I have start_day
and end_day
. 我有学生桌,他们必须每月付款,我有
start_day
和end_day
。
For example: 例如:
start_day = "2018-01-01";
end_day = "2018-03-30";
I want to send an SMS 3 days before pay day. 我想在发薪日前3天发送短信。 I don't know how to fetch those dates in this interval.
我不知道如何在此间隔内获取这些日期。
select user_id from schema.table where end_day between
subdate(current_date, interval 3 day) and subdate(current_date, interval 2 day);
A bad way to do this would be : where date(end_day) = current_date-3
一个糟糕的方法是:
where date(end_day) = current_date-3
Why I don't prefer the bad way (although it looks simple): 为什么我不喜欢坏方法(尽管看起来很简单):
joins
and where
clause. joins
和where
子句上使用函数。 This'll prevent indexes (if any) from being used and will give you nightmares in terms of performance. -
is an arithmetic operator. -
是算术运算符。 It's generally not a good practice to use +/-
with dates. +/-
通常不是一个好习惯。 Use the functions intended to manipulate dates. subdate, date_add, date_sub
etc) subdate, date_add, date_sub
等)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.