CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2460|Reply: 7

Function date & workingday .php

[Copy link]
Post time 28-10-2008 11:27 AM | Show all posts |Read mode
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[IDpelanggan];
$digitalSTD                                            =$_REQUEST[digitalSTD];
$ortorectify                                           =$_REQUEST[ortorectify];
$pansharpen                                         =$_REQUEST[pansharpen];
$pansharpenpnc                                   =$_REQUEST[pansharpenpnc];
$mosaic                                                =$_REQUEST[mosaic];
$hardcopydesignjetprint                       =$_REQUEST[hardcopydesignjetprint];
$hardcopyphotographicprint                =$_REQUEST[hardcopyphotographicprint];
$bilpegawaiproses                                 =$_REQUEST[bilpegawaiproses];
$tarikhkelulusancpp                              =$_REQUEST[tarikhkelulusancpp];
$tarikhpohon                                        =$_REQUEST[tarikhpohon];
$rujukan                                               =$_REQUEST[rujukan];

//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 by  cloud_hardcore at 29-10-2008 09:06 AM ]
Reply

Use magic Report


ADVERTISEMENT


Post time 29-10-2008 12:45 AM | Show all posts
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
Reply

Use magic Report

 Author| Post time 29-10-2008 09:04 AM | Show all posts

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...
Reply

Use magic Report

 Author| Post time 31-10-2008 02:58 PM | Show all posts
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...
Reply

Use magic Report

Post time 31-10-2008 05:47 PM | Show all posts
aduh aku biasa buat guna java.. itu pun buat sebab org yg suh..
Reply

Use magic Report

 Author| Post time 31-10-2008 10:33 PM | Show all posts
urm..klu PHP xtau ke???
Reply

Use magic Report

Follow Us
 Author| Post time 4-11-2008 02:01 PM | Show all posts
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...
Reply

Use magic Report

Post time 4-11-2008 05:14 PM | Show all posts
ko just edit coding yg aku kasi tu... sure boleh punya...........
faham kan function date && timestamp tu
Reply

Use magic Report


ADVERTISEMENT


You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

9-1-2025 07:23 PM GMT+8 , Processed in 1.168640 second(s), 21 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list