Skip to content

Instantly share code, notes, and snippets.

@blacklizard
Last active August 16, 2016 14:53
Show Gist options
  • Save blacklizard/f90aa250b483f85fa358e888f15bd5ac to your computer and use it in GitHub Desktop.
Save blacklizard/f90aa250b483f85fa358e888f15bd5ac to your computer and use it in GitHub Desktop.
prorate
<?php
// dummy data
$start = new DateTime('-9 month');
$expiry = new DateTime("+3 month");
$package_a = 399;
$package_b = 699;
// expiry day does not count thus the substrction of one day
$days = ($expiry->diff($start)->format("%a")) - 1;
$remaining_days = ($expiry->diff(new DateTime("NOW"))->format("%a")) - 1;
// $payable containes the amount that need to be paid
$payable = round($package_b - (
$package_a - (
($package_a / $days) * ($days - $remaining_days))
) , 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment