Current location: Hot Scripts Forums » Programming Languages » PHP » How to add time?


How to add time?

Reply
  #1 (permalink)  
Old 05-19-04, 03:39 PM
clintre clintre is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
How to add time?

I have wrote a script that manages the downtime reports for our major systems. I want to be able to add the time.

currently when I add

01:45:00 and 00:40:00

I get 01:85:00

How to I go about adding the time so that it takes in to account 60 minutes/seconds per hour?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-19-04, 04:07 PM
Lost Lost is offline
Wannabe Coder
 
Join Date: Mar 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by clintre
I have wrote a script that manages the downtime reports for our major systems. I want to be able to add the time.

currently when I add

01:45:00 and 00:40:00

I get 01:85:00

How to I go about adding the time so that it takes in to account 60 minutes/seconds per hour?
Ummm...you will probably multiply the minutes by 60 and hours by 360 and add it and divide it all by 360...just use some math
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-20-04, 01:35 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

It sounded interesting, so I wrote up something for you.

PHP Code:

<?php


function add_time($t1$t2) {
    
// This doesn't have to be explode(), as long as you can explode $t2 into pieces (like substr()'s).
    
$t2 explode(':'$t2);
    
// hh:mm:ss date format. strtotime() will add $t2 components to $t1.
    
return date('H:i:s'strtotime($t1.' + '.$t2[0].' hours '.$t2[1].' minutes '.$t2[2].' seconds'));
}

// Test vars.
$t1 '01:45:00';
$t2 '00:40:00';

// Returns "02:25:00"
echo add_time($t1$t2);

?>
It worked for me.

[EDIT]
Typo and miscomment. Excuse me.
__________________
Blavv =|

Last edited by blaw; 05-20-04 at 01:42 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit the form submission according to time bionicsamir PHP 7 05-10-04 12:10 AM
cant add more than 1 mysql table with php script chrisb62 PHP 1 04-27-04 05:00 AM
time Alii Script Requests 2 03-20-04 12:31 PM
Reduce the time intensive phases of .Net application development using TierDeveloper3 smars General Advertisements 0 12-02-03 06:15 AM
Showing time is users time zone? Nasimov PHP 1 11-20-03 08:14 AM


All times are GMT -5. The time now is 09:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.