tjyoung
asked on
Figure out the duration between 2 time columns in mysql table
Hi,
I have a table that contains two dates formatted like this:
I have a campaign_start_time: 2011-10-08 19:56:35
and a campaign_end_time: 2011-10-08 20:22:37
I'm trying to figure out how to get duration of time between the 2. Essentially my campaign_duration.
And how to extract just the dates without the times?
Any idea how to accomplish this?
thanks tj
I have a table that contains two dates formatted like this:
I have a campaign_start_time: 2011-10-08 19:56:35
and a campaign_end_time: 2011-10-08 20:22:37
I'm trying to figure out how to get duration of time between the 2. Essentially my campaign_duration.
And how to extract just the dates without the times?
Any idea how to accomplish this?
thanks tj
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Trying to work it out but am getting this error:
Call to a member function diff() on a non-object
Bascially doing this with the code since my start and end dates are set:
$interval = $campaignstart->diff($camp aignend);
$interval->format('%d days, %h hours, %i minutes');
See anything obvious?
Call to a member function diff() on a non-object
Bascially doing this with the code since my start and end dates are set:
$interval = $campaignstart->diff($camp
$interval->format('%d days, %h hours, %i minutes');
See anything obvious?
Have you tried the first solution? What was the problem with it?
ASKER
running your exact code as a standalone also creates the same error.
ASKER
Hi,
The first solution was more of a direction to 'go and learn all about this' as opposed to 'here is the relevant code that solves your issue'. Which is why I tried the second one. Unfortunately that doesn't seem to work for some reason.
I'll take another look at the link.
The first solution was more of a direction to 'go and learn all about this' as opposed to 'here is the relevant code that solves your issue'. Which is why I tried the second one. Unfortunately that doesn't seem to work for some reason.
I'll take another look at the link.
ASKER
Wait a minute, I didn't even notice the code.. duh.
checking it now. I just saw the link.
checking it now. I just saw the link.
ASKER
Works perfect.
thanks!
thanks!
ziceva: i think he wants more than just seconds.
your code should be, if your missing first 2 lines
your code should be, if your missing first 2 lines
$sdate = new DateTime($campaignstart);
$edate = new DateTime($campaignend);
$interval = $edate->diff($sdate);
echo $interval->format('%d days, %h hours, %i minutes')."\n";
ok maybe not lol
Open in new window