有没有办法使用 Carbon 显示胎龄?

Is there a way to display Gestational age using Carbon?

{{ \Carbon\Carbon::parse($data_row->birth_date)->floatDiffInRealYears().' y/o' }}

输出:

59.08 y/o

我想要这样的东西:

54 years and 32 weeks
$daysPerYear = 365.24; // Can be the precision you need
$days = $date->floatDiffInRealDays();
$years = floor($days / $daysPerYear);
$remainingDays = $days - $years * $daysPerYear;
$weeks = floor($remainingDays / 7);

echo "$years years and $weeks weeks";

如果需要,您还可以使用 CarbonInterval 将其翻译成其他语言并获得自动复数形式:

echo CarbonInterval::years($years)->weeks($weeks)->locale('it')