Hello all,

What I want is to divide a string in timeformat, lets say 27:30. How can I do that? Eventually I can use SQL for it, because the string comes from the database.

Thanks before!

Recommended Answers

All 8 Replies

I have tried this in MySQL by the way:

TIMEDIFF(TIMEDIFF(u.hour_end, u.hour_begin),TIME(l.u_contract) / 5) AS contract

And this does not work.

Anyone?

What exactly do you want ? How is the value stored in the database and how do you want to split it ?

No I want to divide it. Simple dividing a number that is in timeformat, e.g. 37:40 / 5. For example.

Note that is 37 hours and 40 minutes.

Like this?

list($hrs, $mins) = explode(":", $time);
$mins += $hrs * 60;
$endresult = $mins/5;
echo $endresult;

You make a little mistake I think, the code you are showing must be, I think:

list($hrs, $mins) = explode(":", $time);
$mins += $hrs / 60;
$endresult = $hrs/5;
echo $endresult;

This code is not what I actually intended, because when you take for exampble the time 37:00, you get with the code above as $endresult: 7.4. And the $result must be 7:24.

<?php
$time = "37:00";
list($hrs, $mins) = explode(":", $time);
$mins += $hrs * 60;
$endresult = $mins/5;
echo date("H:i",mktime(0,$endresult,0,0,0,0));
?>

Now ?

commented: Thankyou +1
commented: He gives me a complete solution, thanks nav33n! +1

You make a little mistake I think, the code you are showing must be, I

Actually it does exactly what I was thinking:
27:30
(30 + (27 * 60)) / 5 = 330 minutes

commented: He helped me kindfull +1

Thanks Nav33n and R0bb0b for the kindfull answer.
You where right, and it is working now.

Again thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.