Link to home
Start Free TrialLog in
Avatar of excinc
excinc

asked on

PHP: Counting minutes from dates in array

I have lot's of data printed out from oracle database to array. Some datarows have dates, some only zero.
So I have this kind of data:


02.06.2006 10:11:06
0
0
02.06.2006 20:42:52
03.06.2006 21:04:21
0
0
0
04.06.2006 13:57:28
0
0



So, how can I count minutes from those dates like this:
02.06.2006 10:11:06 - 02.06.2006 20:42:52     is xxx minutes
02.06.2006 20:42:52 - 03.06.2006 21:04:21     is xxx minutes
03.06.2006 21:04:21 - 04.06.2006 13:57:28     is xxx minutes


So those dates are some kind of startimes. And I need to count two different startimes different in minutes.

I can't do it myself :(
ASKER CERTIFIED SOLUTION
Avatar of merwetta1
merwetta1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of excinc
excinc

ASKER

I didn't get that work. It printed nothing :(


Actually when I have this kind of data printed out:

02.06.2006 10:11:06
0
0
02.06.2006 20:42:52
03.06.2006 21:04:21
0
0
0
04.06.2006 13:57:28



I need it to be listed excatly like this:

first group duration xxx min
0
0
second group duration xxx min
third group duration xxx min
0
0
0
04.06.2006 13:57:28
that's odd. when i run it, i get:

02.06.2006 10:11:06 - 02.06.2006 20:42:52 is 631.77 minutes
03.06.2006 21:04:21 - 04.06.2006 13:57:28 is 44,153.12 minutes

the script could easily be modified to give you the exact output you're looking for, but since it's not working for you, that won't help. hopefully someone else can provide something that will work for you.
A PHP script that printed nothing is a strong indicator of a syntax error.  Check the error log (for me at least its /var/adm/httpd.error_log).
-FM
Avatar of excinc

ASKER

It works, sorry, my bad :)

Dates were in wrong format in array :-)
Avatar of excinc

ASKER

But, one thing...

That prints this like you said:


02.06.2006 10:11:06 - 02.06.2006 20:42:52 is 631.77 minutes
03.06.2006 21:04:21 - 04.06.2006 13:57:28 is 44,153.12 minutes



It should be like this:

02.06.2006 10:11:06 - 02.06.2006 20:42:52 is 631.77 minutes
02.06.2006 20:42:52 - 03.06.2006 21:04:21  time is where?????????????????????
03.06.2006 21:04:21 - 04.06.2006 13:57:28 is 44,153.12 minutes      should be 17h x 60min = about 1020min not 44k 153min????
To get the intermediate one, change:
$time1 = 0;
to
$time1 = $time2;


Looks like the answer was given in American date format (MM.DD.YYYY), so 03.06 is about a month (~43,000 min) after 02.06.

For European date format (DD.MM.YYYY), just change the last line from:
$time_unix = mktime($matches[4], $matches[5],  $matches[6],  $matches[1],  $matches[2],  $matches[3]);
     return $time_unix;
to
$time_unix = mktime($matches[4], $matches[5],  $matches[6],  $matches[2],  $matches[1],  $matches[3]);
     return $time_unix;

-FM
Okay, it's not quite the last line, but close.
-FM