Dates, daylight savings and netdaysworked

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gil

    Dates, daylight savings and netdaysworked

    I'm trying to mimic the functionality of netdaysworked in excel. The
    code below works, except when the date starts during daylight savings
    time. what is the number of seconds in a day for a daylight savings
    day?

    thanks,
    gil

    for ($dayval = $startdate; $dayval <=$enddate; $dayval+=$oneda y){
    if (date(I,$dayval )==0){
    echo("daylight savings time<br>");
    }


    if(date(w,$dayv al)==0){
    $daysworked = $daysworked+0;
    }
    elseif(date(w,$ dayval)==6){
    $daysworked = $daysworked+0;
    }
    else{
    $daysworked++;
    }
    echo("first day: ".$dayval." number of days ".($dayval/86400)."
    lastday : ".$lastday. "day of week :".date(w,$dayv al)."date: ".date("m-
    d-Y",$dayval). " days worked: ".$daysworked." <br><br>");
    }

  • Gil

    #2
    Re: Dates, daylight savings and netdaysworked

    On Jun 21, 1:42 pm, Gil <gilbert.mil... @gmail.comwrote :
    I'm trying to mimic the functionality of netdaysworked in excel. The
    code below works, except when the date starts during daylight savings
    time. what is the number of seconds in a day for a daylight savings
    day?
    >
    thanks,
    gil
    >
    for ($dayval = $startdate; $dayval <=$enddate; $dayval+=$oneda y){
    if (date(I,$dayval )==0){
    echo("daylight savings time<br>");
    }
    >
    if(date(w,$dayv al)==0){
    $daysworked = $daysworked+0;
    }
    elseif(date(w,$ dayval)==6){
    $daysworked = $daysworked+0;
    }
    else{
    $daysworked++;
    }
    echo("first day: ".$dayval." number of days ".($dayval/86400)."
    lastday : ".$lastday. "day of week :".date(w,$dayv al)."date: ".date("m-
    d-Y",$dayval). " days worked: ".$daysworked." <br><br>");
    }
    I solved the problem...

    $sm = date("m",$start date);
    $sd = date("d",$start date);
    $sy = date("Y",$start date);
    $em = date("m",$endda te);
    $ed = date("d",$endda te);
    $ey = date("Y",$endda te);


    $stjd = gregoriantojd($ sm,$sd,$sy);
    $edjd = gregoriantojd($ em,$ed,$ey);


    echo ("julian start date: ".$stjd."<br>") ;
    echo ("julian end date: ".$edjd."<br>") ;
    echo ("days between :".($edjd-$stjd)."<br>");


    for ($dayval = $stjd; $dayval <=$edjd; $dayval+=1){

    if (jddayofweek($d ayval)==0){
    $daysworked = $daysworked+0;
    }
    elseif (jddayofweek($d ayval)==6){
    $daysworked = $daysworked+0;
    }
    else{
    $daysworked++;
    }

    Comment

    Working...