Steve,
Consider using the "w" parameter in the date() function to retrieve the
number of days between a given day of the week and Sunday (the first day of
the week).
$today = mktime();
$days_since_sunday = date('w', $today);
With this info, you can build an array of days for the next seven days
starting on that Sunday:
for($i = 0; $i < 7; $i++) {
$days[$i]['stamp'] = mktime(0, 0, 0, date('n', $today),
(date('j', $today) + $i - $days_since_sunday), date('Y', $today));
$days[$i]['pretty_date'] = date('g:i:s a, F j, Y', $days[$i]['stamp']);
}
If you need this calendar for some other week, just offset the mktime()
function by the appropriate number of days:
$today = mktime(0, 0, 0, date('n'), (date('j') - 7*$num_weeks_ago),
date('Y'));
HTH,
Zac
"Steve Fitzgerald" <sfmnetsys.com> wrote in message
news:f1885463.0307090221.61946259posting.google.c om...$result[$i]=array('wday'=>$dateArray['wday'],'week'=>$week,'timestamp'=>$tim> The below code works greate for displaying a monthly calendar, but I'm
> trying to modify it so that it only shows a seven day week calendar.
> What should I do to modify it.
>
> <?php
> function getDaysInMonth($thisYear,$thisMonth){
> $date=getdate(mktime(0,0,0,$thisMonth+1,0,$thisYea r));
> return $date["mday"]+1;
> }
> function getArrayMonth($datetime){
>
> //get basic month information and initialize starter
> values.
> $dateArray = getdate($datetime);
> $mon = $dateArray['mon'];
> $year = $dateArray['year'];
> $numDaysInMonth = getDaysInMonth($year,$mon);
> $week=1;
>
>
> //for each day, get the current day's information and
> store in a result array
> // for that day, the week and the day of the week.
> //finally if that day is the last day of the week,
> start a new week.
> for ($i=1; $i < $numDaysInMonth;$i++){
>
> $timestamp = mktime(0,0,0,$mon,$i,$year);
> $dateArray = getdate($timestamp);
>
estamp);> if ($dateArray['wday']==6){
> $week=$week+1;
> }
> }
>
> return $result;
>
> }
> function getHTMLCalendar($datetime){
> $arrayCalendar = getArrayMonth($datetime);
> print "<TABLE>\n";
> $week=1;
> print "<tr>";
> //add initial padding to month
> for ($start=1;$start<=$arrayCalendar[1]['wday'];
> $start=$start+1)
> print "<td></td>";
>
>
> // for each day make a cell with
> $lastday=1; //use for end month padding later
> foreach ($arrayCalendar as $day => $result) {
> //if we change weeks, start a new row
> if ($week!=$result['week']){
> print "<td></tr><tr>"; //week row
> $week=$result['week'];
> }
> //start day cell
> print "<td>";
> print "<table>";
> print "<tr><td>";
>
> print date("D M j Y", $result['timestamp']);
> print "</td></tr>";
> print "<tr><td>";
> print "Put content here";
> print "</td></tr>";
> print "</table>";
> print "</td>\n"; //end day cell
> $lastday = $day;
> }
>
>
> //add final padding
> for ($start=1;$start<=6-$arrayCalendar[$lastday]['wday'];
> $start=$start+1)
> print "<td></td>";
>
> print "</tr>\n";
>
> print "</TABLE>\n";
> }
> getHTMLCalendar(time());
>
> ?>
>
> THanks.
Bookmarks