Page 1 of 1
Have a problem with counting numbers!
Posted: Tue Jun 27, 2006 5:13 am
by AshrakTheWhite
what this code does is give the start and end date of the given week of year
what i need it to do is count FROM the start date TO the end date of the numbers, aka count out the dates in the given week.
any help is appretiated!
Code: Select all
function findWeekPeriod($week, $year)
{
$aPeriod = array();
$startDay = 'Mon';
$endDay = 'Sun';
$startdate = strtotime('+' . $week . ' week',mktime(0,0,0,1,1,$year));
$enddate = $startdate;
while(date("D",$startdate) != $startDay){
$startdate = mktime(0,0,0,date("m",$startdate),date("d",$startdate)-1, date("Y",$startdate));
}
while(date("D",$enddate) != $endDay){
$enddate = mktime(0,0,0,date("m",$enddate),date("d",$enddate)+1, date("Y",$enddate));
}
return array('start' => date('l d/m/y', $startdate),
'end' => date('l d/m/y', $enddate));
}
Posted: Tue Jun 27, 2006 6:43 am
by JayBird
I read your question a couple of times but still not sure what you are trying to achieve
Posted: Tue Jun 27, 2006 7:47 am
by jayshields
I think he wants to be able to pass a week number (1-52) and a year to a function and it should return the start and end dat of that week.
For example, if he passed week 1 and any year it would return 01/01/xx and 07/01/xx.
I'm not sure how to help you, but I'm sure someone will reply with something helpful soon

Posted: Tue Jun 27, 2006 7:50 am
by AshrakTheWhite
nvm got it working
Code: Select all
function findWeekPeriod($week, $year)
{
$startDay = 'Mon';
$endDay = 'Sun';
$startdate = strtotime('+' . $week . ' week',mktime(0,0,0,1,1,$year));
$enddate = $startdate;
while(date("D",$startdate) != $startDay){
$startdate = mktime(0,0,0,date("m",$startdate),date("d",$startdate)-1, date("Y",$startdate));
}
while(date("D",$enddate) != $endDay){
$enddate = mktime(0,0,0,date("m",$enddate),date("d",$enddate)+1, date("Y",$enddate));
}
$days_in_month = cal_days_in_month(CAL_GREGORIAN, date('n', $startdate), date('Y', $startdate));
$startdate = date('j', $startdate);
$enddate = date('j', $enddate);
$return = array();
$i = $startdate;
while ($i <> $enddate+1)
{
$return[] = $i;
if ($i == $days_in_month)
{
$i = 0;
}
$i++;
}
return $return;
}
Posted: Fri Jun 30, 2006 3:13 am
by AshrakTheWhite
hey got yet another problem!
i need this function to return a timestamp instead of what its returning at the moment, i tryed doing it in the while loops but the PC ran out of memory doing it (64MB on server allocated)
heres the code:
Code: Select all
function findWeekPeriod($week, $year)
{
$startDay = 'Mon';
$endDay = 'Sun';
$startdate = strtotime('+' . $week . ' week',mktime(0,0,0,1,1,$year));
$enddate = $startdate;
while(date("D",$startdate) != $startDay){
$startdate = mktime(0,0,0,date("m",$startdate),date("d",$startdate)-1, date("Y",$startdate));
}
while(date("D",$enddate) != $endDay){
$enddate = mktime(0,0,0,date("m",$enddate),date("d",$enddate)+1, date("Y",$enddate));
}
$days_in_month = cal_days_in_month(CAL_GREGORIAN, date('n', $startdate), date('Y', $startdate));
$startdate = date('j', $startdate);
$enddate = date('j', $enddate);
$return[0] = '0';
$i = $startdate;
while ($i <> $enddate)
{
$return[] = $i;
if ($i == $days_in_month)
{
$i = 0;
}
$i + 1;
}
unset($return[0]);
#$return['start'] = $startdate;
#$return['end'] = $enddate;
return $return;
}
Posted: Sun Jul 02, 2006 5:25 pm
by shiznatix
well i dont know exactally how your time is being returned in the array but turn it into a string and use mktime on it
http://ee2.php.net/manual/en/function.mktime.php also look at the other functions in the manual about getting a unix time stamp.
a print_r() or the return would be helpful to help you figure out how to make that time a unix time stamp.
Posted: Mon Jul 03, 2006 3:24 am
by AshrakTheWhite
well the time being returne is just a date number aka
Code: Select all
0 => 28
1 => 29
3 => 30
4 => 1
5 => 2
6 => 3
what i need is it to return a timestamp for each of those dates