3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function yearlyDays($a, $b) { //Takes in two dates and returns the decimal of days per year for that specific year // I made this in order to fix the issue of leap years. $aYearDay = date("z", strtotime($a)) + 1; $aYearDays = date("z", strtotime(date("Y", strtotime($a))."-12-31")) + 1; $aPercent = $aYearDay/$aYearDays; $bYearDay = date("z", strtotime($b)) + 1; $bYearDays = date("z", strtotime(date("Y", strtotime($b))."-12-31")) + 1; $bPercent = $bYearDay/$bYearDays; if(date("Y", strtotime($a))!=date("Y", strtotime($b))) { //a percent is .6 in the year 2013 leap year //b percent is .7 in the year 2012 $aPercent += abs(date("Y", strtotime($a))-date("Y", strtotime($b))); print $aPercent; } return $aPercent-$bPercent; } print yearlyDays("2012-05-12", "2013-05-12");
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
1.36338797814211.0017441425256