NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page (php) Help Needed for addition of two variables Urgent...

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-26-2007, 04:19 AM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Dec 2005
Location: India
Posts: 274
raju79 will become famous soon enoughraju79 will become famous soon enough
 



(php) Help Needed for addition of two variables Urgent...


I need to sum two variable each of them have time in time format how can i add them to have result in the same time format.

$c1 = 29:00:00
$c2 = 05:10:00


$c = $c1 + $c2;

when i echo $c it gives result as 34
But i need result as 34:10:00

Please help me out.


Thanks
raju79 is offline  
Old 05-26-2007, 04:33 AM   #2 (permalink)
Senior Member
 
tristanperry's Avatar
Join Date: Jan 2007
Location: Wales - United Kingdom
Posts: 1,774
tristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant future
 




This isn't exactly working.. not too sure why. Although the basic concept behind this is:

1) Convert both times to their UNIX timestamp
2) Add together
3) Output as a time.

I came up with this:

Code:
<?php
$c1 = "29:00:00";
$c2 = "05:10:00";

$Newc1 = mktime($c1);
$Newc2 = mktime($c2);

$NewTime = $Newc1 + $Newc2;

echo date ('G:i:s', $NewTime);

?>
- although it's not working exactly?
tristanperry is offline  
Old 05-26-2007, 05:31 AM THREAD STARTER               #3 (permalink)
NamePros Regular
Join Date: Dec 2005
Location: India
Posts: 274
raju79 will become famous soon enoughraju79 will become famous soon enough
 



Yes it is not working i am stuck very badly please help me out i need to solve this problem.
raju79 is offline  
Old 05-26-2007, 05:58 AM   #4 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,558
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
Actually Tristanperry is on the righ track but there are several arguments for the mktime function:
http://php.net/mktime
Basically you need to split your string and extract hour, minute, second and pass these arguments to mktime
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline  
Old 05-26-2007, 06:00 AM   #5 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
nvmd.
Eric is offline  
Old 05-26-2007, 06:00 AM   #6 (permalink)
Senior Member
 
tristanperry's Avatar
Join Date: Jan 2007
Location: Wales - United Kingdom
Posts: 1,774
tristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant futuretristanperry has a brilliant future
 




Ah good point.. so the string needs to be exploded..

Code:
<?php
$c1 = "29:00:00";
$c1 = explode(':', $c1);
$c2 = "05:10:00";
$c2 = explode(':', $c2);

$Newc1 = mktime($c1[0],$c1[1],$c1[2]);
$Newc2 = mktime($c2[0],$c2[1],$c2[2]);

$NewTime = $Newc1 + $Newc2;

echo date ('G:i:s', $NewTime);

?>
Something like that... wait, what are the original times formatted as?
????: NamePros.com http://www.namepros.com/programming/332168-php-help-needed-addition-two-variables.html

29:00:00 - is that Hours : Minutes : Seconds

Like a stop-watch or something? What are you intending to actually get by adding

29:00:00 to 05:10:00?
Last edited by tristanperry; 05-26-2007 at 06:05 AM.
tristanperry is offline  
Old 05-26-2007, 11:19 AM   #7 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
As tristanperry asked is that days, hours and minutes or maybe hours, minutes and seconds it could also be minutes, seconds and milliseconds.

It may sound pedantic but it is vital information if you want some help. For example if it is the 1st option then the following is the maximum possible:-

364:23:59

with the second the following shows the maximum digits:-

23:59:59

and in the 3rd:-

59:59:999

of course the 1st digit in each may not make a difference but would of course depend on your usage.
Peter is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:06 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger