Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating with date/time

Status
Not open for further replies.

Annie12345

Programmer
Jun 1, 2004
6
NL
Hi, Can anyone help me to make a sql query (for a php website/administrating system) in which to calculate with date and time??
There is: Userid, Begintime, Endingtime and Date. I have to get the hours a month (how much the person has worked that month). So userid x has worked y hours in january... rather nasty... Any help is welcome!
 
Something like this ?
SELECT Userid, Month(Date) AS Month, Sum(Endingtime-Begintime) AS TotalHours
FROM theTable
GROUP BY Userid, Month(Date)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It doesn't work yet. It says:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\webserver\apache\htdocs\proj7\compsystems\med\uren_viewer.php on line 78

This is (a part of) the code I have now:

$query = "SELECT month(date) AS month sum(eindtijdwerken-begintijdwerken) AS totaaltijd FROM uren $order_by_str $sort_order_str $limit_str";
$result = mysql_query($query);
?>
<?php
while($query_data = mysql_fetch_array($result)) {
$urennr = $query_data["urennr"];
$gebruikernr = $query_data["gebruikernr"];
$month = $query_data["month"];
$totaltime = $query_data["totaltime"];

echo "<TR ALIGN='CENTER'>\n";
echo "<TD WIDTH=\"23%\">$urennr</TD>\n";
echo "<TD WIDTH=\"24%\">$gebruikernr</TD>\n";
echo "<TD WIDTH=\"24%\">$month</TD>\n";
echo "<TD WIDTH=\"24%\">$totaltime</TD>\n";
echo "<TD WIDTH=\"5%\">
<A HREF=\"javascript:eek:pen_window('med/uren_bekijken.php?action=view_record&urennr=$urennr');\">bekijken</A></TD>\n";
echo"</TR>\n";
}?>

Don't mind the wierd names, it's in dutch... uren=hours tijd=time gebruiker=user :)
Tnx for your time!
 
Code:
SELECT Userid, m as "Month", 
Sum((Endingtime-Begintime) hour(4)) as workedHours
from (select userid, extract(month from "DATE") as m,
Endingtie, begintime
from t) as dt
 GROUP BY Userid, m
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top