Jump to content

Recommended Posts

MSQL 5.1.36

PHP 5.3.0

 

I have my php script that tried to add number of hours for

each division on a particular date.

For example , I want to find the number of hours worked

by IT division from $start_date = "2010-07-01" to $end_date = "2010-07-04". 

 

Lets say there are 4 IT staff working on the start date "2010-07-01", I want to calculate their hours add them up and store it into the array. After that I have to increment date and do another calculation for IT staff i.e calculate their hours and them up and store into the same array....

 

and I want the output to be somethings like this

 

2010-07-01  2010-07-02  2010-07-03  2010-07-04

  50 hrs            20hrs            43.5hrs        45.2hrs

 

50 hrs is the total hours by IT in 2010-07-01

20 hrs is the total hours by IT in 2010-07-02

and so on....

 

This is what i did so far with my code....

 

$start_date = "2010-07-01";

$end_date = "2010-07-04";

$next_date = $start_date;

 

while ($line = mysql_fetch_array($employee_hrs, MYSQL_ASSOC))

{

      if($line['dept_num'] == "D01" && $line['ts_date'] ==  $next_date)//IT

    {

 

        $it_hours = calculateTimeDifference($line['ts_timein'],$line['ts_timeout']);

        $it_Total_hours = $it_Total_hours + $it_hours;

        $it_array[] = $it_hours;

 

    }

   

  $next_date =strftime("%Y-%m-%d", strtotime("$start_date +$i day"));

  $i++;

}//end while loop

 

The problem with the above code is that it cannot calcuate

the total hours for each separate date . It  only returns a sum of total hours from $start_date up to $end_date.

 

Thanks in advance....

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/208007-compare-dates/
Share on other sites

if($line['dept_num'] == "D01" ...

 

^^^ You generally don't want to ever loop through the records your query returns and filter the results using some php code. You should just select just the data you want in your query and if you actually wanted to do this for ALL or just a range/list of departments, you would also do that in your query using a GROUP BY.

 

It would help if you posted your query and showed how your ts_timein and ts_timeout are defined, because you can likely do everything in a single query and then just iterate over the date/total hours values.

Link to comment
https://forums.phpfreaks.com/topic/208007-compare-dates/#findComment-1087356
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.