Jump to content

[SOLVED] convert decimal (?) to time


gusaps

Recommended Posts

Hi...

 

I'm programing something like this... (I'm really a beginner on PHP)

 

http://www.airrouting.com/content/TimeDistanceForm.aspx

 

I have already most of the code on my PHP...

 

but when come to the simplest I cannot find the answer...

 

after the time duration:

 

$duration = $distNM / 400; // distance in nautical miles / per 400 knots average speed

 

I need to show the time in a nice way... like HH:MM, and I cannot find the way to convert the decimals from the formula to time... I guess must be an easy way on the date & time functions but i cannot find it...

 

I need some help on this...

 

Thanks in advance...

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/127520-solved-convert-decimal-to-time/
Share on other sites

So what you're getting is something like "5.8641 Hours" and you want to convert it into "5 Hours + X minutes" ?

This should do:

 

<?php

$num_hours = 5.8641; //some float
$hours = floor($num_hours);
$mins = round(($num_hours - $hours) * 60);
echo $hours." Hours and ".$mins." minutes";

?>

 

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.