cloud_hardcore Publish time 28-10-2008 11:27 AM

Function date & workingday .php

Salam...
aku de wat satu sistem ni..untuk insert data yang lain da ok da...
cume yg duedate tu aku nk buat function kire hari bekerja.aku guna php ng mysql je..
sape leh tolong plz reply thread ni..
ni contoh coding yg aku da buat...
yg aku kaler tu yg aku nk wat la...

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php
include('configure.php');//ni connection aku da declare awal2//

//yg bawah ni request dari form yg da di isi..
$IDpelanggan                                        =$_REQUEST;
$digitalSTD                                          =$_REQUEST;
$ortorectify                                           =$_REQUEST;
$pansharpen                                       =$_REQUEST;
$pansharpenpnc                                 =$_REQUEST;
$mosaic                                                =$_REQUEST;
$hardcopydesignjetprint                     =$_REQUEST;
$hardcopyphotographicprint                =$_REQUEST;
$bilpegawaiproses                                 =$_REQUEST;
$tarikhkelulusancpp                              =$_REQUEST;
$tarikhpohon                                        =$_REQUEST;
$rujukan                                             =$_REQUEST;

//CALCULATION PART//
$bilhariproses                         = (($digitalSTD*4)+($ortorectify*4)+($pansharpen*5)+($pansharpenpnc*5)+($mosaic*12)+($hardcopydesignjetprint*6)+($hardcopyphotographicprint*7));

$bilhariprosesperpegawai         = ($bilhariproses/$bilpegawaiproses);

//working day ni untuk masuk dalam proses pengiraan
$duedate                        =workingday($tarikhpohon$bilhariprosesperpegawai);

//echo "bil hari proses ialah :".$bilhariproses;

$query1="insert into proseskerja(IDpelanggan,digitalSTD,ortorectify,pansharpen,pansharpenpnc,mosaic,hardcopydesignjetprint,hardcopyphotographicprint,bilhariproses,bilpegawaiproses,bilhariprosesperpegawai,duedate,tarikhkelulusancpp,tarikhpohon,rujukan)               values('$IDpelanggan','$digitalSTD','$ortorectify','$pansharpen','$pansharpenpnc','$mosaic','$hardcopydesignjetprint','$hardcopyphotographicprint','$bilhariproses','$bilpegawaiproses','$bilhariprosesperpegawai','$duedate','$tarikhkelulusancpp','$tarikhpohon','$rujukan')";
mysql_db_query($dbname, $query1);
//echo"$query1";
echo "Data successfully added to database ";
?>
<a href="form_akaun.php?idpelanggan=<?php echo $IDpelanggan; ?>">Seterusnya</a>

[ Last edited bycloud_hardcore at 29-10-2008 09:06 AM ]

BorderManager Publish time 29-10-2008 12:45 AM

alamak pening aku baca coding ko....
n aku kasi kot leh membantu.. takleh gak... pm aku

<?php
//The function returns the no. of business days between two dates and it skeeps the holidays
function getWorkingDays($startDate,$endDate,$holidays){
    //The total number of days between the two dates. We compute the no. of seconds and divide it to 60*60*24
    //We add one to inlude both dates in the interval.
    $days = (strtotime($endDate) - strtotime($startDate)) / 86400 + 1;

    $no_full_weeks = floor($days / 7);
    $no_remaining_days = fmod($days, 7);

    //It will return 1 if it's Monday,.. ,7 for Sunday
    $the_first_day_of_week = date("N",strtotime($startDate));
    $the_last_day_of_week = date("N",strtotime($endDate));

    //---->The two can be equal in leap years when february has 29 days, the equal sign is added here
    //In the first case the whole interval is within a week, in the second case the interval falls in two weeks.
    if ($the_first_day_of_week <= $the_last_day_of_week){
      if ($the_first_day_of_week <= 6 && 6 <= $the_last_day_of_week) $no_remaining_days--;
      if ($the_first_day_of_week <= 7 && 7 <= $the_last_day_of_week) $no_remaining_days--;
    }
    else{
      if ($the_first_day_of_week <= 6) $no_remaining_days--;
      //In the case when the interval falls in two weeks, there will be a Sunday for sure
      $no_remaining_days--;
    }

    //The no. of business days is: (number of weeks between the two dates) * (5 working days) + the remainder
//---->february in none leap years gave a remainder of 0 but still calculated weekends between first and last day, this is one way to fix it
   $workingDays = $no_full_weeks * 5;
    if ($no_remaining_days > 0 )
    {
      $workingDays += $no_remaining_days;
    }

    //We subtract the holidays
    foreach($holidays as $holiday){
      $time_stamp=strtotime($holiday);
      //If the holiday doesn't fall in weekend
      if (strtotime($startDate) <= $time_stamp && $time_stamp <= strtotime($endDate) && date("N",$time_stamp) != 6 && date("N",$time_stamp) != 7)
            $workingDays--;
    }

    return $workingDays;
}

//Example:

$holidays=array("2006-12-25","2006-12-26","2007-01-01");

echo getWorkingDays("2006-12-22","2007-01-06",$holidays)
// => will return 8
?>

**credit to www.php.net

cloud_hardcore Publish time 29-10-2008 09:04 AM

Balas #2 BorderManager\ catat

bro...koding yg aku bg tu untuk proses insert je...
utk form aku guna koding lain...
yg bro bg ni aku xpasti nk panggil workingdays macam mane...
nnt aku edit koding ni letak komen supaya bro paham...

cloud_hardcore Publish time 31-10-2008 02:58 PM

xde org nk reply ke???
aku dah dapat nk cari tempoh mase bekerja then aku nak dapat kan tarikh selepas masa bekerja...


$bilhariprosesperpegawai//ni adalah bilangan hari untuk kerja
$tarikhpohon    //ni adalah tarikh mula bekerja

so yang aku nk tahu tarikh selepas kerja selesai...
plz sape2 yg tahu btau aku...

liverpoolfctv Publish time 31-10-2008 05:47 PM

aduh aku biasa buat guna java.. itu pun buat sebab org yg suh..

cloud_hardcore Publish time 31-10-2008 10:33 PM

urm..klu PHP xtau ke???

cloud_hardcore Publish time 4-11-2008 02:01 PM

skrg ni aku dah ley dpt duedate..tp die xkire working day...ari cuti pun maen langgar gak...so nk tolak mase cuti tu cmne erk...

BorderManager Publish time 4-11-2008 05:14 PM

ko just edit coding yg aku kasi tu... sure boleh punya...........
faham kan function date && timestamp tu
Pages: [1]
View full version: Function date & workingday .php


ADVERTISEMENT