Jump to content

Recommended Posts

I have collected some data from .xml api's and I need to manipulate it in a way to display something specific.

 

not my strongest point when it comes to maths & date data.

 

so ultimately I need it to echo something like the following:

 

"3 Days 4 Hours Remaining" or "14 Hours Remaining" (if below 24 hours!!!)

 

I use the following to pull my variables and to test by echo results.

	<?php  // Calculate total Fuel blocks
		$itemID = $record['itemID']; 
		$result = mysql_query("SELECT * FROM `ecmt_poslistdetails` WHERE itemID = '$itemID' AND (typeID='4051' OR typeID='4247' OR typeID='4246' OR typeID='4312')");
		$row = mysql_fetch_array($result);
		$fuelQty = $row[quantity]; 
		echo $fuelQty; 
	?>
        <br />
	<?php // Calculate total Fuel blocks used per hour
		$typeID = $record['typeID']; 
		$result = mysql_query("SELECT * FROM `ecmt_posfuel` WHERE typeID = $typeID");
		$row = mysql_fetch_array($result);
        $fuelUse = $row['fuel'];
		echo $fuelUse;
	?>

this gives me:

 

$fuelQty & $fuelUse

 

so for instance if fuel quantity is: 18480

and $fuelUse is: 40

 

the fuel used is 40x per hour and time remaining would be 462x Hours remaining but I want it to display: 19 Days 6 Hours Remaining

 

how can I achieve this format?

let the dateTime and dateInterval classes do the work for you

$fuel = 18480;
$fuelUse = 40;
$hrs = $fuel/$fuelUse;

$dt1 = new DateTime("+$hrs hours");
$dif = $dt1->diff(new DateTime());   // $dif is a dateInterval object

echo $dif->d . ' days ';
echo $dif->h . ' hours ';
echo $dif->m . ' minutes';
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.