Display 7 day calenday

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Fitzgerald

    Display 7 day calenday

    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,$this Month){
    $date=getdate(m ktime(0,0,0,$th isMonth+1,0,$th isYear));
    return $date["mday"]+1;
    }
    function getArrayMonth($ datetime){

    //get basic month information and initialize starter
    values.
    $dateArray = getdate($dateti me);
    $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,$m on,$i,$year);
    $dateArray = getdate($timest amp);
    $result[$i]=array('wday'=> $dateArray['wday'],'week'=>$week, 'timestamp'=>$t imestamp);
    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;$star t<=$arrayCalend ar[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;$star t<=6-$arrayCalendar[$lastday]['wday'];
    $start=$start+1 )
    print "<td></td>";

    print "</tr>\n";

    print "</TABLE>\n";
    }
    getHTMLCalendar (time());

    ?>

    THanks.
  • Zac Hester

    #2
    Re: Display 7 day calenday

    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_sun day = 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_sun day), 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_ag o),
    date('Y'));

    HTH,
    Zac


    "Steve Fitzgerald" <sf@mnetsys.com > wrote in message
    news:f1885463.0 307090221.61946 259@posting.goo gle.com...[color=blue]
    > 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,$this Month){
    > $date=getdate(m ktime(0,0,0,$th isMonth+1,0,$th isYear));
    > return $date["mday"]+1;
    > }
    > function getArrayMonth($ datetime){
    >
    > //get basic month information and initialize starter
    > values.
    > $dateArray = getdate($dateti me);
    > $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,$m on,$i,$year);
    > $dateArray = getdate($timest amp);
    >[/color]
    $result[$i]=array('wday'=> $dateArray['wday'],'week'=>$week, 'timestamp'=>$t im
    estamp);[color=blue]
    > 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;$star t<=$arrayCalend ar[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;$star t<=6-$arrayCalendar[$lastday]['wday'];
    > $start=$start+1 )
    > print "<td></td>";
    >
    > print "</tr>\n";
    >
    > print "</TABLE>\n";
    > }
    > getHTMLCalendar (time());
    >
    > ?>
    >
    > THanks.[/color]


    Comment

    Working...