0

I need to count the total working days but there is problem with it. When I count the different it will return to me a certain decimal number like 19660.9708, I don't know what is wrong with the function since some of it return the right value of different like 2,3,4 and all. Thats is actually only the first problem, the 2nd problem is the value will be return either with extra 1 day or less one day.

if(isset($_GET[Submit]))
{ 
/*********************************************************/

 $tarikh = $tarikh[6].$tarikh[7].$tarikh[8].$tarikh[9]."-".$tarikh[3].$tarikh[4]."-".$tarikh[0].$tarikh[1];
 $jumlah = 0;
 $no = 0;
 $tarikh1 = $_GET[tarikh1];
 $tarikh2 = $_GET[tarikh2];
 $bank = $_GET['bank'];
 $tarikh1 = $tarikh1[6].$tarikh1[7].$tarikh1[8].$tarikh1[9]."-".$tarikh1[3].$tarikh1[4]."-".$tarikh1[0].$tarikh1[1];
 $tarikh2 = $tarikh2[6].$tarikh2[7].$tarikh2[8].$tarikh2[9]."-".$tarikh2[3].$tarikh2[4]."-".$tarikh2[0].$tarikh2[1];
   
 $query = "select * from transaksi_inden where tarikh_kerani >= '$tarikh1' and tarikh_kerani <= '$tarikh2' order by tarikh_kerani asc";
 $result = mysql_query($query);
 if(mysql_errno()>0)
  {
   die("MySQL error ". mysql_errno(). ": ".mysql_error());
  }
 $i = 1;
 while($row = mysql_fetch_assoc($result))
 {
 $bil++;
 $query1 = "select * from penyelenggaraan_syarikat where kod_syarikat = '".$row['id_con']."'";
  $result1 = mysql_query($query1);
  $row1 = mysql_fetch_assoc($result1);
  $supplier = $row1['nama_syarikat'];
  
  $query_holiday = "select SUM(bil) as bil from cuti_umum where tarikh_mula >= '$row[tarikh_terima]' and tarikh_tamat <= '$row[tarikh_kerani]' ";
  $result_holiday = mysql_query($query_holiday);
  $row_holiday  = mysql_fetch_assoc($result_holiday);
  $holidays = $row_holiday['bil']; 
  $holidays = $$holidays = '' ? 0 : $holidays;

  $jumlah = $jumlah + $row['amaun_inden'];
  if($row['amaun_inden'] >= '20001'){
     
   $check1 = '';
   $check2 = '';
      
   $hari = getWorkingDays($row['tarikh_terima'],$row['tarikh_serah_suydp'],$holidays);
   $tt++;
   
   if($hari <= 4 &&  $hari >= 0)
  {
   $check1 = 'checked.png';
   $check2 = 'uncheck.png';
   $ttc++;
  }
  else
  {
   $check1 = 'uncheck.png';
   $check2 = 'checked.png';
   $tta++;

  }
  }

   //$check1 =  $hari <= 3 ? 'checked.png' : 'uncheck.png';
   //$check2 =  $hari >= 4 ? 'checked.png' : 'uncheck.png';
   //$ttc++;
  //}
  else{
   //5 hari
   //tarikh semak
   $tarikh_terima_kewangan = "";
   $check1 = '';
   $check2 = '';
   $hari = getWorkingDays($row['tarikh_pemilihan'],$row['tarikh_serah_suydp'],$holidays);
   $tt++;
   
   if($hari <= 5 &&  $hari >= 0)
  {
   $check1 = 'checked.png';
   $check2 = 'uncheck.png';
   $ttc++;
  }
  else
  {
   $check1 = 'uncheck.png';
   $check2 = 'checked.png';
   $tta++;

  }
  }

   //$check1 =  $hari <= 3 ? 'checked.png' : 'uncheck.png';
   //$check2 =  $hari >= 4 ? 'checked.png' : 'uncheck.png';
   //$ttc++;
  //}
  
   if(empty($row['tarikh_serah_suydp'])){
   $hari='-';
   $check1 = 'uncheck.png';
   $check2 =  'uncheck.png';
   //$tta++;
  } 
  //tarikh_serah_suydp->tarikh_serah_J.pelaksana
     $row_data[] = array($bil,$row['no_inden'],$supplier,numberFormatComma($row['amaun_inden'],2),convertDateSys($row['tarikh_pemilihan']),convertDateSys($row['tarikh_terima']),convertDateSys($row['tarikh_serah_suydp']),$hari,$check1,$check2,$catiran);

 }
 {
  $query2 = "select COUNT(id) as num, SUM(amaun_inden) as amn from transaksi_inden where amaun_inden >= 20000.01 and tarikh_kerani >= '$tarikh1' and tarikh_kerani <= '$tarikh2' order by tarikh_kerani asc";
 $result2 = mysql_query($query2);
 $row_amt2= mysql_fetch_array($result2);
 $data1 = $row_amt2['num'];
 $data2 = $row_amt2['amn'];
 
 }
 {
  $query3 = "select COUNT(id) as num4, SUM(amaun_inden) as amn from transaksi_inden where amaun_inden <= 20000.00 and tarikh_kerani >= '$tarikh1' and tarikh_kerani <= '$tarikh2' order by tarikh_kerani asc";
 $result3 = mysql_query($query3);
 $row_amt3= mysql_fetch_array($result3);
 $data4 = $row_amt3['num4'];
 $data5 = $row_amt3['amn'];
 }

This is the function that I use during the submit.

function getWorkingDays($startDate,$endDate,$holidays)
 {
  $days = (strtotime($endDate) - strtotime($startDate)) / 86400;
  $no_full_weeks = floor($days / 7);
  $no_remaining_days = fmod($days, 7);
 
  $the_first_day_of_week = date("N",strtotime($startDate));
  $the_last_day_of_week = date("N",strtotime($endDate));
 
  if($the_first_day_of_week <= $the_last_day_of_week)
  {
   if($the_first_day_of_week <= 5 && 5 <= $the_last_day_of_week) $no_remaining_days--;
   if($the_first_day_of_week <= 6 && 6 <= $the_last_day_of_week) $no_remaining_days--;
  }
  else
  {
   if($the_first_day_of_week <= 5) $no_remaining_days--;
   $no_remaining_days--;
  }
 
    $workingDays = $no_full_weeks * 5;
  if($no_remaining_days > 0 )
  {
    $workingDays += $no_remaining_days;
  }
 
  //foreach($holidays as $holiday)
  //{
   $time_stamp=strtotime($holiday);
   if(strtotime($startDate) <= $time_stamp && $time_stamp <= strtotime($endDate) && date("N",$time_stamp) != 5 && date("N",$time_stamp) != 6)
    $workingDays--;
  //}
  return $workingDays;
 }
   

And above is the function that i use to calculate the working days. I need help on this matter. At least how can I solve those problem on the decimal number.

  • Possible duplicate of [Calculate business days](http://stackoverflow.com/questions/336127/calculate-business-days) – t1gor Jan 03 '16 at 14:18
  • These codes are too complex to read, you should find the part causing the problem first. – st. Jan 03 '16 at 14:20
  • `mysql_*` functions are deprecated since PHP 5.5 (and removed entirely in PHP 7) and you shoud [stop using them](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) if you can. – Qirel Jan 03 '16 at 14:22

0 Answers0