Unstoppable Domains โ€” Expired Auctions

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

SpaceshipSpaceship
Watch

raju79

Established Member
Impact
6
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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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?
 
0
•••
Yes it is not working i am stuck very badly please help me out i need to solve this problem.
 
0
•••
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 ;)
 
0
•••
nvmd.
 
0
•••
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?

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:
0
•••
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.
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back