Skip to content

Instantly share code, notes, and snippets.

@moeseth
Created January 3, 2017 03:31
Show Gist options
  • Save moeseth/66602f8b69bb6f6fce56ca82e8fdae34 to your computer and use it in GitHub Desktop.
Save moeseth/66602f8b69bb6f6fce56ca82e8fdae34 to your computer and use it in GitHub Desktop.
A php function to calculate pawn months in Myanmar
<?php
function calculate_pawn_months($start_date, $end_date)
{
$start_date = new DateTime($start_date);
$end_date = new DateTime($end_date);
$diff_months = ($start_date->diff($end_date)->m + ($start_date->diff($end_date)->y * 12));
$total_days = $start_date->diff($end_date)->d;
if ($diff_months > 0) {
if ($total_days > 0) {
if ($total_days <= 15) {
$diff_months += 0.5;
} else {
$diff_months += 1;
}
}
} else {
$diff_months = 1;
}
return $diff_months;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment