Jump to content

Total Time Not Displaying Correctly


Moorcam

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

Guys. The problem has been solved last week. You can stop explaining how time works. The OP got it.

 

I know that reading is tough, but when you open a thread, try to at least check the current state. Repeating what everybody else has already said just isn't very helpful.

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. ;)

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

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.