Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Find day difference without weekends in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.44k
    Comment on it

    Using php we can easily find difference in days excluding weekends. First take start date and end date and generate strtotime for these dates to convert into string. After manipulation using while loop we can easily get the count of week days excluding weekend i.e saturday and sunday where date('N') gets the day of the week (1 - Monday, 2-Tuesday, 3-wednesday, 4-thursday,5-friday, 6-saturday, 7 - Sunday)

    $start = strtotime('2012-08-06');
    $end = strtotime('2012-09-06');
    
    $count = 0;
    
    while(date('Y-m-d', $start) < date('Y-m-d', $end)){
      $count += date('N', $start) < 6 ? 1 : 0;
      $start = strtotime("+1 day", $start);
    }
    
    echo $count;
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: