noufalcep noufalcep - 5 months ago 49
PHP Question

How to convert seconds into days hours minutes in Laravel

I want to convert time interval in seconds into days hours minutes. I have tried this.

$value = '90060';

I got the output

90060 seconds

My expected output is

1 day 1 hour 1 minute

How can I get the output using

Answer Source

I got a solution.

$value = '90060';
$dt = Carbon::now();
$days = $dt->diffInDays($dt->copy()->addSeconds($value));
$hours = $dt->diffInHours($dt->copy()->addSeconds($value)->subDays($days));
$minutes = $dt->diffInMinutes($dt->copy()->addSeconds($value)->subHours($hours));
echo CarbonInterval::days($days)->hours($hours)->minutes($minutes)->forHumans();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download