Jump to content

[SOLVED] SUM() problem


savagenoob

Recommended Posts

I want to calculate the sum of rows that fall between 2 dates but its calculating the total of all the rows no matter what dates I select. Here is my code...

<?php
$fquery="SELECT SUM(MinutesClock) FROM timeclock WHERE Employee = '$employee' AND Clock = 'Out' AND Time BETWEEN '$date4' AND '$date3' ";
		$fresult = mysql_query($fquery);
?>

doing an echo on $fquery shows....

"SELECT SUM(MinutesClock) FROM timeclock WHERE Employee = '4' AND Clock = 'Out' AND Time BETWEEN '2009-02-01 00:00:01' AND '2009-03-30 23:59:59'  Total Time Worked: 106 Hours 17 Minutes"

But it shouldnt be 106 hours...it says that no matter what.

Link to comment
Share on other sites

First of all, let's tell MySQL that "Time" isn't a keyword but in fact a fieldname:

$fquery="SELECT SUM(MinutesClock) FROM timeclock WHERE Employee = '$employee' AND Clock = 'Out' AND `Time` BETWEEN '$date4' AND '$date3' ";

 

If you can, work out how many minutes you should be getting back.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.