Number of years passed - Consider leap year

xJeftabx

New Member
In our HR system, we want to calculate the number of years the employee has served the company.What we have is the joining date in \[code\]TIMESTAMP\[/code\] column.What I am doing is:\[code\]$timeNow = time(); // current time$joinDate = strtotime($users->fields['date_of_joining']); // from database$servicePeriod = $timeNow - $joinDate; // in seconds$servicePeriod = $servicePeriod / 31570560; // in years\[/code\]But will this take the leap years into consideration? If an employee joined in \[code\]Feb 27\[/code\] of a leap year and if we check the status next year by \[code\]March 1\[/code\], he should still be reported as served for \[code\]1 year\[/code\] and not \[code\]1 year and 1 day\[/code\].Any ideas on this? Thanks.
 
Back
Top