E
E
Eugene2019-12-03 12:53:14
PHP
Eugene, 2019-12-03 12:53:14

How to convert time from milliseconds to period format?

Good afternoon, the question arose, how to convert the time in milliseconds to the form "1 year 3 months 12 days"?
I tried to do it using the Carbon library, but the library itself thinks this is somehow strange

$start = Carbon::createFromFormat('Y-m-d', '1996-12-06');
$end = Carbon::createFromFormat('Y-m-d', '2019-12-03');
echo (CarbonInterval::milliseconds($start->diffInMilliseconds($end))->cascade())->y;//Выведет, что количество лет 24
echo CarbonInterval::milliseconds($start->diffInMilliseconds($end))->cascade()->forHumans();// Выведет 24 года 11 месяцев 3 недели 4 дня

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question