Page 1 of 1

how to add two date values which are retrieved from mysql?

Posted: Mon Oct 27, 2008 11:49 am
by vidyabhushan
suppose in $time1 and $time2 there is a value of mysql time type and now i want to find out the sum of those two time values and store the sum into a $tot_time how can we do that..

i have done it like below

$tot_time = 0;
$tot_time = $time1 + $time2.

but the above code is not working... how to do that then???? please help me..... thanx in advance.....

Re: how to add two date values which are retrieved from mysql?

Posted: Mon Oct 27, 2008 11:57 am
by aceconcepts
Take a look at

Code: Select all

strtotime()
Something like this should help:

Code: Select all

$xTime=strtotime("+$time1 minutes", $time2);

Re: how to add two date values which are retrieved from mysql?

Posted: Mon Oct 27, 2008 12:16 pm
by vidyabhushan
now i did it like this...

Code: Select all

 
$time1 = '0:20:0';
    $time2 = '0:40:0';
    $tot_time=strtotime("+$time1 minutes", $time2);
    print $tot_time
 
still its not working...

Re: how to add two date values which are retrieved from mysql?

Posted: Mon Oct 27, 2008 12:25 pm
by aceconcepts
I was giving that code as an illustration, look up strtotime() in the PHP manual - you'll learn more if you reseach it.

Re: how to add two date values which are retrieved from mysql?

Posted: Mon Oct 27, 2008 1:54 pm
by Hannes2k
Hi,
or split the time into it parts (explode) and uses mktime().

Re: how to add two date values which are retrieved from mysql?

Posted: Mon Oct 27, 2008 3:28 pm
by VladSun
vidyabhushan wrote:suppose in $time1 and $time2 there is a value of mysql time type and now i want to find out the sum of those two time values and store the sum into a $tot_time how can we do that..

i have done it like below

$tot_time = 0;
$tot_time = $time1 + $time2.

but the above code is not working... how to do that then???? please help me..... thanx in advance.....
What about performing it directly in the DB query?

Re: how to add two date values which are retrieved from mysql?

Posted: Mon Oct 27, 2008 8:31 pm
by vidyabhushan
Thank you all... I did it using explode() funtion...Thank you all again...