巧用strtotime函数计算日期

在以前做一个项目开发的时候遇到一个需求,已知宠物的生日是2011-08-01,宠物每三个月会驱虫一次,提示用户下次给宠物驱虫的时间。

下面是我这边想的一个方法,使用strtotime函数轻松解决。其实平时真的很少这样使用,PHP函数真的好强大!

< ?php

$birthday = strtotime('2011-08-03');

while(time() > $birthday)
{
    $birthday = strtotime('+3 Months', $birthday);
}

echo date('Y-m-d', $birthday);

你可能感兴趣的:(strtotime)