Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    finding total weekends for the current year

    hi,
    how can i get total weekends falling in the current year

    Thanks
    Bhakti Thakkar

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    The best I could come up with ...

    But you need to really define what a weekend is.
    Both Saturday and Sunday, or count one of those days as a weekend?

    Same with days,
    01/01/2006 --> 12/31/2006 or 01/01/2006 --> 01/01/2007
    How you specify one year could end up adding 1 extra weekend.

    It all depends on how you look at it.

    PHP Code:
    <?php

    $date1
    ="01/01/2006";
    $date2="12/31/2006";

    $days_between=dateDiff("/"$date2$date1);
    $weekends=$days_between/7;

    echo 
    "Days Between Dates: $days_between";
    echo 
    "<br><br>";
    echo 
    "Weekends: $weekends";

    function 
    dateDiff($dformat$endDate$beginDate)
    {
    $date_parts1=explode($dformat$beginDate);
    $date_parts2=explode($dformat$endDate);
    $ts1=mktime(000$date_parts1[0], $date_parts1[1], $date_parts1[2]);
    $ts2=mktime(000$date_parts2[0], $date_parts2[1], $date_parts2[2]);
    $difference $ts2-$ts1;
    $diffday $difference/86400;
    $startday=date(w,$ts1); //day of week
    $endday=date(w,$ts2); //day of week

    // do some calculations here on whether or not the first day is
    // Sunday (therefore, considered a full weekend?
    // You'll have to determine what you want to count as a weekend.
    // (Sunday=0, Saturday=6)
    // Same with the last day, what if Dec 31 is a Saturday?

    return $diffday;
    }

    ?>
    Last edited by mlseim; 10-27-2006 at 02:35 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •