尝试#1
第一种方法是最好的:你比较两个日期年(在你的情况 - 日期时间)。本年必须比最后日期的年份更大:2010 - 2014年那你比较相同,但有一些更精确的日,月:条件
$current = time();
$last = strtotime("2010-04-19 08:20:45");
$years_diff = (int) date("Y", $current) - (int) date("Y", $last);
$months_diff = (int) date("n", $current) - (int) date("n", $last);
$days_diff = (int) date("j", $current) - (int) date("j", $last);
$condition = false;
if ($years_diff == 1) { // ABOUT one year ago when last plan was created
if ($months_diff == 0) { // Current month is month when plan was created
if ($days_diff >= 0) { // Larger than or equal to day when last plan was created
$condition = true;
}
}
else if ($months_diff > 0) { // Next months in new year
$condition = true;
}
}
else if ($years_diff > 1) { // ABOUT 2 or more years ago when last plan was created
$condition = true;
}
还有的压缩版本:
$condition = (($years_diff == 1) ? (($months_diff == 0) ? ($days_diff >= 0) : ($months_diff > 0)) : ($years_diff > 1));
尝试#2
简单的方法是计算拉斯之间的差t和当前日期(在你的情况下 - “datetime”)。然后检查差异是否大于或等于365天。
$current = time();
$last = strtotime("2010-04-19 08:20:45");
$days_diff = ($current - $last)/(60 * 60 * 24);
$condition = ($days_diff >= 365);
'$ prevYear = SUBSTR($阵列[3],4);如果($ prevYear ==日期('Y')){' – Daan 2014-09-01 10:24:41
你想检查数组中已经存在的值吗? – 2014-09-01 10:24:45
@punithasubramaniv是的 – 2014-09-01 10:25:42