Answer the question
In order to leave comments, you need to log in
Running cron with conditions?
PHP:
// время создания сущности в UNIX-формате (напр., 150123456)
$time_created = $entity->time_created;
// сегодня
$today = time();
// выясняю день/месяц/год создания сущности
$d = date('j',$time_created);
$m = date('n',$time_created);
$y = date('Y',$time_created);
// указываю течение 3-го, 6-го и 7-го дня с момента создания сущности
$three_days = mktime(0, 0, 0, $m, $d+3, $y);
$six_days = mktime(0, 0, 0, $m, $d+6, $y);
$seven_days = mktime(0, 0, 0, $m, $d+7, $y);
if($today == $three_days) {
// тут логика
}
if($today == $six_days) {
// тут логика
}
if($today == $seven_days) {
// тут логика
}
if($today >= $three_days) {
// тут логика
}
Answer the question
In order to leave comments, you need to log in
Your comparison is not correct. The date should not be equal to your $three_days, but be between it and 11:59 pm on the same day.
Also, it is better to work with DateTime, where there is DateTime::diff, DateTime::add, etc., it is much more convenient, clearer and more concise than any mktime|date, etc.
if($today == $three_days)
You are expecting a match to the second
, but
And at the same time
mktime(0, 0, 0, $m, $d+3, $y);i.e. 00:00
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question