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
Share on other sites

hi Orio, thanks for your interest.... I see what u mean...

 

The result I get is in hours... because 400 knots per hour is how i measure the speed on the equation... is about 740km/h or 460miles/h

 

Is that what you need?

 

thanks

 

 

 

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.