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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vidyabhushan
Forum Newbie
Posts: 16
Joined: Mon Oct 20, 2008 4:58 pm

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

Post 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.....
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

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

Post by aceconcepts »

Take a look at

Code: Select all

strtotime()
Something like this should help:

Code: Select all

$xTime=strtotime("+$time1 minutes", $time2);
vidyabhushan
Forum Newbie
Posts: 16
Joined: Mon Oct 20, 2008 4:58 pm

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

Post 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...
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

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

Post 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.
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

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

Post by Hannes2k »

Hi,
or split the time into it parts (explode) and uses mktime().
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

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

Post 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?
There are 10 types of people in this world, those who understand binary and those who don't
vidyabhushan
Forum Newbie
Posts: 16
Joined: Mon Oct 20, 2008 4:58 pm

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

Post by vidyabhushan »

Thank you all... I did it using explode() funtion...Thank you all again...
Post Reply