2016-12-29 66 views
0

我需要一個php腳本,每隔一年從給定的開始日期變量執行任務。PHP |每隔一年

例子:

$start_year = 2011 and $current_year = 2016 => don't perform task 
$start_year = 2012 and $current_year = 2016 => perform task 
$start_year = 2013 and $current_year = 2016 => don't perform task 
$start_year = 2014 and $current_year = 2016 => perform task 
$start_year = 2015 and $current_year = 2016 => don't perform task 

如何檢查,如果當前年份是從開始日期每隔一年時間內?

回答

5

只需將開始的年份減去當前的年份並檢查其是偶數還是奇數。

if((($current_year - $start_year) % 2) == 0){ 
    //perform task 
    } 
+0

當然,爲什麼我沒有想到這個?!謝謝! – iamfredrik