Jump to content

Total Time Not Displaying Correctly


Moorcam
Go to solution Solved by Jacques1,

Recommended Posts

Howdy,

 

I am using the following code to get the total hours and minutes from multiple input fields. It works fine. However, the final result is displaying the time as:

24.5:30

Where it should be displaying as:

24:30

Here is the code:

$day1hours = $mondiff;
$day2hours = $tudiff;
$day3hours = $weddiff;
$day1 = explode(":", $day1hours);
$day2 = explode(":", $day2hours);
$day3 = explode(":", $day3hours);

$totalmins = 0;
$totalmins += $day1[0] * 60;
$totalmins += $day1[1];
$totalmins += $day2[0] * 60;
$totalmins += $day2[1];
$totalmins += $day3[0] * 60;
$totalmins += $day3[1];

$hours = $totalmins / 60;
$minutes = $totalmins % 60;

$totalhours = "$hours:$minutes";

If anyone can spot something that is causing the .5 please show me. I am about to be driven to drinking all the Guinness available in Victoria.

Link to comment
Share on other sites

 

No shit. How about you read the friggin' replies? Let me try again:

 

You need to do an integer division.

 

 

 

Integer division. That means cutting off the fractional part. Like you did in elementary school. 30/60 is 0.5. But intdiv(30, 60) is 0. Because 30 = 0 × 60 + 30.

 

Jacques1, you having a bad day? I like you so I will forgive you. I did not start shouting abuse at you so do not throw it at me. Okay? :)

 

So, now that it made more sense, it is working. Thank you. ;)

Edited by DanEthical
Link to comment
Share on other sites

My answer had two sentences. Two. When you don't even bother to read two sentences and instead repeat the question as if I was an idiot, then, yes, I'll be less patient than I was the first time.

 

If this was a complex problem with a long answer which cannot be processed in one go, I could see how you might miss some information. But not reading two sentences to me is a sign of disrespect.

Link to comment
Share on other sites

My answer had two sentences. Two. When you don't even bother to read two sentences and instead repeat the question as if I was an idiot, then, yes, I'll be less patient than I was the first time.

 

If this was a complex problem with a long answer which cannot be processed in one go, I could see how you might miss some information. But not reading two sentences to me is a sign of disrespect.

That's a bit harsh there mate. I read both sentences. However, after driving for 22 hours it made less sense than a chicken crossing the road. My apologies if I seemed disrespectful. Your repeat of those two sentences were what one would call disrespectful along with many other answers I see you give people.

We come here for a reason mate, that is to get help with something we are stuck with. We don't come here to get abused. If you do not want to help people, don't post.

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.