开发者

From month to month and year

开发者 https://www.devze.com 2023-01-09 06:59 出处:网络
For example, I have the month 1开发者_运维问答3 and I want to convert it to 1 year and 1 month with php.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消