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 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    Calculate monday - friday total minutes

    Let's say I'm given a date range like so 12/01/2009 - 02/5/2010. How can I total the total minutes of only the monday - friday dates of that date range???

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    It's probably a bit clunky but how about something like this:

    Code:
    <?php
    $start	= mktime(0, 0, 0, 1, 12, 2009);
    $end	= mktime(0, 0, 0, 5, 2, 2010);
    $current = $start;
    $days_count = 0;
    while ($current < $end){
    	$day_of_week = date('N', $current);
    	if ($day_of_week < 6 ){
    		$days_count++;
    	}
    	$current += 86400;
    }
    $minutes_count = ($days_count*24)*60;
    echo $minutes_count;
    ?>

  • #3
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts
    Not sure it's working. I tried the below but I get 130 for the $days_count.


    <?php
    $start = mktime(0, 0, 0, 21, 2, 2010);
    $end = mktime(0, 0, 0, 27, 2, 2010);
    $current = $start;
    $days_count = 0;
    while ($current < $end){
    $day_of_week = date('N', $current);
    if ($day_of_week < 6 ){
    $days_count++;
    }
    $current += 86400;
    }
    $minutes_count = ($days_count*24)*60;
    echo $days_count;
    ?>

  • #4
    New to the CF scene
    Join Date
    Feb 2010
    Location
    Williamsburg, VA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have your day and month backwards:

    mktime(0, 0, 0, 21, 2, 2010)

    should be

    mktime(0, 0, 0, 2, 21, 2010)


  •  

    Posting Permissions

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