note 105064 deleted from function.date by tularis
| From: | tularis@php.net | Date: | Thu, 09 Feb 2012 20:50:23 +0000 |
| Subject: | note 105064 deleted from function.date by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185953@lists.php.net to get a copy of this message | ||
Note Submitter: joseph_robert_martinez at yahoo dot com
----
Now, this works for me, as our week starts on Fri, not Sun, and takes in account of the day light
savings time issues that I was having when displaying the days in a calendar format.
This takes an array of dates from a mysql query, and displays them in a calendar style view
<?php
$cDates = count($Dates);
for($k = 1; $k <= $cDates-2; $k++)
{
$t = $k; $p = $t + 1;
$start = strtotime($Dates[$k]["DTG"]);
$stop = strtotime($Dates[$p]["DTG"]);
$dayTotal = ($stop - $start)/24/60/60;
$date = date("Y-m-d", $start); // starting date (YYYY-MM-DD)
$temp = date("Y-m-d", $stop); // ending date (YYYY-MM-DD)
$end = date("Y-m-d",strtotime("-1 day",$stop));
echo "\n<table style=\"align:center;width:100%;\">";
echo "\n <tr>";
echo "\n <th colspan=\"7\"
align=\"center\"><strong>";
echo "\n </strong></th>";
echo "\n </tr>";
echo "\n <tr>";
echo "\n <th>Fri</th>";
echo "\n <th>Sat</th>";
echo "\n <th>Sun</th>";
echo "\n <th>Mon</th>";
echo "\n <th>Tue</th>";
echo "\n <th>Wed</th>";
echo "\n <th>Thu</th>";
echo "\n </tr>";
echo "\n <tr>";
$offset = date("w", strtotime($date));
if($offset <= 4) // to add spaces to beginning of row
{
for($i = 0; $i <= $offset+1; $i++){echo "\n <td><br
/></td>";}
$count = $offset+2;
}
else
{
$count = 0;
}
while($date <= $end)
{
echo "\n <td>" . date("d M", strtotime($date))
."::". date("w",strtotime($date)). "</td>";
$date = date('Y-m-d',strtotime("$date +1 day")); // get the next date
if($count >= 6) // to set next row
{
$count = 0;
echo "\n </tr><tr>";
}
else
{
$count++;
}
}
for($i = $count; $i <= 6; $i++){echo "\n <td><br
/></td>";}// to add spaces at end of row
echo "\n </tr>";
echo "\n</table>";
}
?>