Jump to content

which day is belong which week


davids701124

Recommended Posts

I have generate days between 2 dates, the code is following:

 

$day = 24 * 60 * 60;

$sTime = strtotime('2009-10-20'); //it doesn't work putting $row["user_registered"]

$eTime = strtotime('2010-08-10'); //it doesn't work putting $row["user_registered"]

$numDays = (($eTime - $sTime) / $day + 1);

$numWeeks =  $numDays / 7;

 

print $numWeeks;

 

and now I wanna create a table; the row is week number, ex: week1, week2,...;the column is day, from Mon to Sun. and each field will contain exactly date, ex: 2009-10-20....

 

So I'm wondering how can I know which day is belong which week?

Link to comment
https://forums.phpfreaks.com/topic/178370-which-day-is-belong-which-week/
Share on other sites

Hi

 

I presume you want a list of table of them.

 

Something like this will do it, but not that efficient (the strfrtime to determine the day of the week could be coded round if you wanted):-

 

$DayCnt = 0;
for($aCnt = $sTime ; $aCnt <= $eTime ; $aCnt += 86400)
{
$DayOfWeek = strftime('%w',$aCnt );
if ($DayOfWeek != $DayCnt)
{
	echo '<tr>';
	for($DayCnt = 0 ; $DayCnt < $DayOfWeek ; $DayCnt++)
	{
		echo '<td> </td>';
	}
}
echo '<td>'.strftime('%d/%b/%Y',$aCnt ).'</td>';
$DayCnt++;
if ($DayCnt >= 7)
{
	$DayCnt = 0;
	echo '</tr>';
}
}

for($aCnt = $DayCnt ; $DayCnt < 7 ; $aCnt++)
{
echo '<td> </td>';
}
echo '</tr>';

 

This is days from Sun to Sat.

 

All the best

 

Keith

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.