我需要一些帮助,有没有办法根据日期在一个月内倒计时4周?并根据日期告诉用户4周重播?又过了一个星期,他说有“3周”等等。 如果用户到达日期,请告诉他(例如,如果您不付款,您的帐户将会结束)。当我设置另一个日期时,倒计时再次开始......每周一次,直到结束日期。感谢
答案 0 :(得分:0)
以下是使用datediff
的解决方案:
set @var := date '2016-04-30';
select
case when (@remaining := datediff(@var, curdate())) > 4 * 7 then ''
when @remaining > 3 * 7 then '4 weeks remaining'
when @remaining > 2 * 7 then '3 weeks remaining'
when @remaining > 1 * 7 then '2 weeks remaining'
when @remaining > 0 * 7 then '1 weeks remaining'
else 'time is up'
end as `Remaining reminder`;
mysql> set @var := date '2016-04-30';
Query OK, 0 rows affected (0.00 sec)
mysql> select
-> case when (@remaining := datediff(@var, curdate())) > 4 * 7 then ''
-> when @remaining > 3 * 7 then '4 weeks remaining'
-> when @remaining > 2 * 7 then '3 weeks remaining'
-> when @remaining > 1 * 7 then '2 weeks remaining'
-> when @remaining > 0 * 7 then '1 weeks remaining'
-> else 'time is up'
-> end as `Remaining reminder`;
+--------------------+
| Remaining reminder |
+--------------------+
| 4 weeks remaining |
+--------------------+
1 row in set (0.00 sec)
将@var更新为目标date
。
答案 1 :(得分:0)
这是另一个简单的解决方案。提供到期日期(帐户结束的日期)和当前日期。
function get_weeks_remaining($date, $expire_date){
$difference = strtotime($expire) - strtotime($date);
return floor($difference / 604800);
}
以下是解决方案ideaone
PS:604800是7天/ 1周内的秒数