From month to month and year
For example, I have the month 1开发者_运维问答3 and I want to convert it to 1 year and 1 month with php. 26 - 2 years and 2 months. How to "convert" it?
$totalmonths = 26;
$years = floor($totalmonths/12);
$months = $totalmonths % 12;
echo $years, " year", $years==1?"":"s";
if ($months != 0)
echo " and ", $months, "month", $months==1?"":"s";
Divide by 12 and take integer part and modulus separately.
精彩评论