Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8775827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:54:06+00:00 2026-06-13T18:54:06+00:00

I am trying to make this overview of work hours However I can’t get

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:54:07+00:00Added an answer on June 13, 2026 at 6:54 pm

    Convert both dates to unix timestamps, then return the difference in hours.

    SELECT (UNIX_TIMESTAMP(end) - UNIX_TIMESTAMP(start)) / 60.0 / 60.0 as hours_difference
    

    No need for any PHP calculations after that…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make this peace of code work. But I get the Fatal error.
Im trying to make this work with jQuery var ng = $.get('/static/views/ng.html'); $('#myHeader').insertBefore(ng); the
I'm trying to make this many-to-many join work with Flask-SQLAlchemy and two MySQL databases,
I am trying to make this sample program work (defn foo ([x] (foo x
I'm trying to make this request to the RunKeeper API : GET /user HTTP/1.1
I'm trying to make this fragment work: Version History --------------- These are the versions
I am trying to make this code bellow to work, I would really appreciate
I'm trying to make this code work but it won't. Somebody help me please.
I am trying to make this jquery carousel work with different widths. Right now
I'm trying to make this trigger work: CREATE trigger trig_tbl_art for tbl_art active before

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.