I want to convert time interval in seconds into days hours minutes. I have tried this.
$value = '90060';
CarbonInterval::seconds($value)->forHumans();
I got the output
90060 seconds
My expected output is
1 day 1 hour 1 minute
How can I get the output using Carbon
or CarbonInterval
php //PHP program to convert seconds into //hours, minutes, and seconds $seconds = 6530; $secs = $seconds % 60; $hrs = $seconds / 60; $mins = $hrs % 60; $hrs = $hrs / 60; print ("HH:MM:SS-> " . (int)$hrs .
$time = round($seconds); echo sprintf('%02d:%02d:%02d', ($time/3600),($time/60%60), $time%60);
Total hours divided by the employee's hours per day. For eg, an employee works 8 hours per day. Leave balance for Sick Leave shows as 32 hours. The hours to days conversion will be calculated as 32 / 8 = 4 days.
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)->subDays($days)->subHours($hours));
echo CarbonInterval::days($days)->hours($hours)->minutes($minutes)->forHumans();
Updated Solution
CarbonInterval::seconds(90060)->cascade()->forHumans();
try this
$init = 150065;
$day = floor($init / 86400);
$hours = floor(($init -($day*86400)) / 3600);
$minutes = floor(($init / 60) % 60);
$seconds = $init % 60;
echo "$day:$hours:$minutes:$seconds";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With