# Date

I am trying to do a date calculation and for the most part i have it working

``````\$emp_start = 1161410400 ;

if(\$emp_start <= strtotime("-2 years")) {
echo "Next Date: ". date('F jS, Y', \$emp_start + (strtotime("24 months") - time())) . "<br />" ;
}
elseif (\$emp_start <= strtotime("-18 months")) {
echo "Next Date: ". date('F jS, Y', \$emp_start + (strtotime("18 months") - time())) . "<br />" ;
}
elseif (\$emp_start <= strtotime("-12 months")) {
echo "Next Date: ". date('F jS, Y', \$emp_start + (strtotime("12 months") - time())) . "<br />" ;
}
elseif (\$emp_start <= strtotime("-6 months")) {
echo "Next Date: ". date('F jS, Y', \$emp_start + (strtotime("6 months") - time())) . "<br />" ;
}
elseif (\$emp_start <= strtotime("-3 months")) {
echo "Next Date: ". date('F jS, Y', \$emp_start + (strtotime("3 months") - time())) . "<br />" ;
}

echo date('F jS, Y', \$emp_start) . "<br />" ;``````

now I have the employee start date as Oct 21, 2006
and as of todays date their next review date should be oct 21, 2008

now I know this year is a leap year

but what i am wondering is if there is a way to calculate in a time span how may leapyears there has been and the add that many days to the total
as this is not the entire calculation, reviews are done yearly after the first to years so i will be adding a loop to calculate the rest.

thanks in advance for you help

I am not sure I understand your question…

You want to know how many leap years there have been since WHEN? Since date of hire? Unix Epoch? Beginning of time?

One possible solution is to do a loop around the YEAR(s) in question and check using the DATE function (String of “L” ) to see if it’s a leap year and then make your adjustments accordingly. http://us.php.net/manual/en/function.date.php

Also I would definitely consider getting rid of the if… elseif…elseif…elseif… Scheme in favor of a SWITCH http://us3.php.net/switch

Lastly, a somewhat “Easy” Calculation is to make use of the date and mktime functions (http://us3.php.net/switch and http://us.php.net/manual/en/function.mktime.php ) to do your math. Using the DATE function you grab the YEAR (or month or day, or whatever) only and add or delete as appropriate, then re-create the unix timestamp using the mktime function.

Sponsor our Newsletter | Privacy Policy | Terms of Service