Created
August 16, 2018 15:17
-
-
Save cygeorgel/636f8d5bd6b9e95a0d980eaf68040b35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prorataTemporis($from = '2018-06-15', $to = '2018-08-01') | |
{ | |
$from = new \DateTime($from); | |
$to = new \DateTime($to); | |
$diff = $to->diff($from); | |
$months = $diff->y * 12 + $diff->m; | |
return $months + (1 / $from->format('t') * $diff->d); | |
} | |
print $this->prorataTemporis('2016-06-01') . PHP_EOL; | |
// 26 | |
print $this->prorataTemporis('2018-06-01') . PHP_EOL; | |
// 2 | |
print $this->prorataTemporis('2018-07-15') . PHP_EOL; | |
// 0.54838709677419 | |
print $this->prorataTemporis('2018-07-31') . PHP_EOL; | |
// 0.032258064516129 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment