How to calculate the percentage through the tax year in PHP
Recently a client requested that we display for them a percentage of how far through the tax year we are. I did some looking online however I couldn’t find anything which suited my needs.
Below is the code I ended up writing which will calculate the percentage value and display the output at the end.
$currentMonth = date('n'); $currentYear = date('Y'); $dayInYear = date('z'); $taxYearStartYear = $currentMonth < 4 ? $currentYear - 1 : $currentYear; $taxYearStart = $taxYearStartYear . '-04-01 00:00:00'; $taxYearStartDay = date('z', strtotime($taxYearStart)); $taxDayInYear = $dayInYear < $taxYearStartDay ? ($dayInYear + 365) - $taxYearStartDay : $dayInYear - $taxYearStartDay; $taxYearPassed = ($taxDayInYear / 365) * 100; echo $taxYearPassed.'% of the way through the tax year';