...

View Full Version : Calculate monday - friday total minutes



nikko50
02-26-2010, 04:41 PM
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???

Spudhead
02-26-2010, 05:15 PM
It's probably a bit clunky but how about something like this:


<?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;
?>

nikko50
02-26-2010, 05:27 PM
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;
?>

zulugrid
02-27-2010, 01:40 AM
You have your day and month backwards:

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

should be

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum