Page 1 of 1

Date Loop Problem..

Posted: Wed Jul 09, 2003 4:29 am
by santos_
Im having trouble tweaking this snippet of code below, basically what the code does is it calculates the current position in a week, goes to previous monday and prints twelve weeks(of mondays) into a dropdown box.

e.g:

for the start of this week, (Mon 7th July), it will print the following:
call_date >= '07 July 2003' AND call_date < '14 July 2003'
Which is all ok, but what Id like to also do is populate an array with the dates between (and including) the dates above

e.g:
07 July 2003
08 July 2003
09 July 2003
10 July 2003
11 July 2003
12 July 2003
13 July 2003
14 July 2003
Hope you understand what Im trying to achieve.

Cheers
Santos

Code: Select all

<? 
define("SECONDSINWEEK", 604800); // Number of seconds in week 
define("SECONDSINDAY", 86400); // Number of seconds in day 
$iDayOfWeek = 1; // 0 to 6 - 0 being Sunday 
$iNumWeeks = 12; // Number of weeks to lookback 
$iOffsetTimestamp = 0; // Initialize this var 
$iCurTime = time(); 
$iCurDay = date("w", $iCurTime); 

if ($iCurDay > $iDayOfWeek){ //if we already passed the day we're looking for 

$iOffsetTimeStamp = $iCurTime - (SECONDSINDAY * ($iCurDay - $iDayOfWeek) ); 

}else if($iCurDay == $iDayOfWeek){ //if we're on the day we're looking for 

$iOffsetTimeStamp = $iCurTime; 

}else{ //if the day we're looking for hasn't come up yet 

$iOffsetTimeStamp = ($iCurTime + (SECONDSINDAY * ($iDayOfWeek - $iCurDay) ) ) - SECONDSINWEEK; 
} 
?> 
<b>Week Starting:</b><p> 
<?php 

for ($i =0; $i < $iNumWeeks; $i++) 
{ 

if(stripslashes($_POST['sdate']) == "call_date >= '" . date("d F Y", $iOffsetTimeStamp - ($i * SECONDSINWEEK) ) . "' AND call_date < '" . date("d F Y", ($iOffsetTimeStamp + SECONDSINWEEK) - ($i * SECONDSINWEEK) ) . "'"){ 

echo date("d F Y", $iOffsetTimeStamp - ($i * SECONDSINWEEK) ) . "<br>\n"; 

}else{ 

echo date("d F Y", $iOffsetTimeStamp - ($i * SECONDSINWEEK) ) . "<br>\n"; 

} 

} 

?> 
</select>