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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.