I am trying to make this overview of "work" hours
However I can't get it to calculate the hours between two dates in my sql db, but it wont return the result.
I tried to just display the two SQL entries which worked, but it seems like the calculation wont use the SQL enteries
I am getting this error in the top of my page:
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string (31/10-2012 19:14) at position 0 (3): Unexpected character' in D:\xampp\htdocs\admin.php:46 Stack trace: #0 D:\xampp\htdocs\admin.php(46): DateTime->__construct('31/10-2012 19:1...') #1 {main} thrown in D:\xampp\htdocs\admin.php on line 46 What am I doing wrong here??
The thing I need help to is on line 43-52 Here is my code:
<?php $host="localhost"; $username="xxxx"; $password="xxxx"; $db_name="xxxxx"; $tbl_name="log"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id ASC"; $result=mysql_query($sql); ?> <title>VT Log - Oversigt</title> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="30%" align="center" bgcolor="#E6E6E6"><strong>Navn</strong></td> <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Start</strong></td> <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Slut</strong></td> <td width="30%" align="center" bgcolor="#E6E6E6"><strong>Kommentar</strong></td> <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Tid</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><? echo $rows['user']; ?><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['start']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['end']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['comment']; ?></td> <?php $stamp1 = $rows['start']; $stamp2 = $rows['end']; $date1 = new DateTime($stamp2); $date2 = new DateTime($stamp2); $diff = $date2->diff($date1); $hours = $diff->h; $hours = $hours + ($diff->d*24); ?> <td align="center" bgcolor="#FFFFFF"><? echo $hours;?></td> </tr> <?php } mysql_close(); ?> <tr> <td colspan="5" align="center" bgcolor="#E6E6E6"><?php echo "Total arbejdstid: " . array_sum($numbers) . "\n Timer";?></td> </tr> </table>
$date1and$date2to the same thing?