Re: Date/time format?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2007. 03. 29, csütörtök keltezéssel 16.38-kor Jason Pruim ezt írta:
> Thanks everyone for your suggestions, it turns out it was a unix time  
> stamp and I can get it to parse out a normal date now.
> 
> Now... on to the harder part....
> 
> What I am trying to do is learn... This is kind of just a pet project  
> for me to figure out how I can do it. here is how the database is  
> laid out:
> 
> +-----------+------------+---------------------------------+--------- 
> +----------+
> | user      | day                |  
> job_name                                 | minutes | sequence |
> +-----------+------------+---------------------------------+--------- 
> +----------+
> | root      | 1172466000 | Production & technology Manager |     480  
> |        0 |
> | root      | 1172466000 | Production & technology Manager |     720  
> |        1 |
> | root      | 1172466000 | Production & technology Manager |     750  
> |        2 |
> | root      | 1172466000 | Production & technology Manager |     990  
> |        3 |
> 
> the minutes column is the number of minutes that have passed since  
> midnight. the sequence number refers to the sequence that the times  
> were entered, meaning that 480 minutes after midnight came before 720  
> minutes, which was before 750 minutes which was before 990 minutes.  
> What I need to do, is be able to calculate the time between 0 & 1, 2  
> & 3, 4 & 5 (there is a total of 6 sequences that could be in here)
> 
> here is now the math would like on that particular entry: (480-720) +  
> (750-990)=480/60=8 hours.
> 
> This is a timecard program that I'm trying to write a report for to  
> show the time for the entire month instead of it's default for the  
> week. You can see what I have tried live at: raoset.com/tests/ 
> oatstest/oats.shtml
> 
> the code that I need help with is the math. I have looked but I just  
> can't find a clear way to get the info from mysql, into an array in  
> php to do the math? Maybe I've been looking at it to long and so I'm  
> missing easy stuff?
> 
> I have tried this code:
> $querytime = mysql_query("select sum(minutes) as t1, sum(sequence) as  
> t2 from oats_time");
> while($row = mysql_fetch_array($querytime)){
> $fulltotal=$row['t1']+$row['t2'];
> echo($fulltotal);
> }
>   but that didn't work the way I wanted it to.
> 
> Anyway... Post is long enough to start, so let me know if there is  
> other info you need.

(I assume you want this calculation within one given day)
you could read all rows into an array like

$timeinfo = array();
$sql = "SELECT minute, sequence FROM table WHERE day='$day'";
$result = mysql_query($result);
while ($row = mysql_fetch_assoc($result)) {
	$timeinfo[$row['sequence'] = $row['minute'];
}

and then calculate and echo the difference between any element of the
array:

$diff0_1 = $timeinfo[1] - $timeinfo[0];

greets
Zoltán Németh


> 
> Thanks in advance!
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux