note 105064 added to function.date
| From: | joseph_robert_martinez at yahoo dot com | Date: | Tue, 26 Jul 2011 03:05:24 +0000 |
| Subject: | note 105064 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181869@lists.php.net to get a copy of this message | ||
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>";
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 75.63.8.47
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/105064
Del: integrated -- https://master.php.net/note/delete/105064/integrated
Del: useless -- https://master.php.net/note/delete/105064/useless
Del: bad code -- https://master.php.net/note/delete/105064/bad+code
Del: spam -- https://master.php.net/note/delete/105064/spam
Del: non-english -- https://master.php.net/note/delete/105064/non-english
Del: in docs -- https://master.php.net/note/delete/105064/in+docs
Del: other reasons-- https://master.php.net/note/delete/105064
Reject -- https://master.php.net/note/reject/105064
Search -- https://master.php.net/manage/user-notes.php