User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,495 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,739 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 469 | Replies: 8 | Solved
Reply
Join Date: Jun 2008
Posts: 45
Reputation: kvdd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kvdd kvdd is offline Offline
Light Poster

Divide time

  #1  
Jun 18th, 2008
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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Posts: 45
Reputation: kvdd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kvdd kvdd is offline Offline
Light Poster

Re: Divide time

  #2  
Jun 18th, 2008
I have tried this in MySQL by the way:

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

And this does not work.

Anyone?
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Divide time

  #3  
Jun 18th, 2008
What exactly do you want ? How is the value stored in the database and how do you want to split it ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jun 2008
Posts: 45
Reputation: kvdd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kvdd kvdd is offline Offline
Light Poster

Re: Divide time

  #4  
Jun 18th, 2008
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.
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 759
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 61
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Master Poster

Re: Divide time

  #5  
Jun 18th, 2008
Like this?
list($hrs, $mins) = explode(":", $time);
$mins += $hrs * 60;
$endresult = $mins/5;
echo $endresult;
Last edited by R0bb0b : Jun 18th, 2008 at 11:06 am.
Reply With Quote  
Join Date: Jun 2008
Posts: 45
Reputation: kvdd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kvdd kvdd is offline Offline
Light Poster

Re: Divide time

  #6  
Jun 20th, 2008
You make a little mistake I think, the code you are showing must be, I think:
  1. list($hrs, $mins) = explode(":", $time);
  2. $mins += $hrs / 60;
  3. $endresult = $hrs/5;
  4. 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.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Divide time

  #7  
Jun 20th, 2008
  1. <?php
  2. $time = "37:00";
  3. list($hrs, $mins) = explode(":", $time);
  4. $mins += $hrs * 60;
  5. $endresult = $mins/5;
  6. echo date("H:i",mktime(0,$endresult,0,0,0,0));
  7. ?>
Now ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 759
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 61
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Master Poster

Re: Divide time

  #8  
Jun 20th, 2008
Originally Posted by kvdd View Post
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
Last edited by R0bb0b : Jun 20th, 2008 at 10:35 am.
Reply With Quote  
Join Date: Jun 2008
Posts: 45
Reputation: kvdd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kvdd kvdd is offline Offline
Light Poster

Re: Divide time

  #9  
Jun 21st, 2008
Thanks Nav33n and R0bb0b for the kindfull answer.
You where right, and it is working now.

Again thanks!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:09 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC