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);
$result[$i]=array('wday'=>$dateArray['wday'],'week'=>$week,'timestamp'=>$timestamp);
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. 1 8712
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" <sf@mnetsys.com> wrote in message
news:f1**************************@posting.google.c om... 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);
$result[$i]=array('wday'=>$dateArray['wday'],'week'=>$week,'timestamp'=>$tim
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: StepH |
last post by:
Hi,
I'm building a little application, which the goal is to:
1./ Collect data via Serial line and or via a file (for playback).
2./ Display these data as graph, oscilloscope, ...
How manage...
|
by: FrankBooth |
last post by:
Hello,
I have a list of names, and when I click ona name I want the extar
info to show and then I want to clcik and hide it again.
I have the following HTML which works perfectly if I use one...
|
by: Mat |
last post by:
<div id="container">
<div id="main">
<div id="header">
<p class="Address">123 Fake Street, </p>
<p class="City">Crazy City, </p>
<p class="Province">Ontario </p>
<p class="PostalCode">H0H...
|
by: shreddie |
last post by:
Could anyone assist with the following problem?
I'm using JavaScript to hide/show table rows depending on the option
selected in radio buttons. The script works fine in IE but in Firefox
the...
|
by: Tristan Miller |
last post by:
Greetings.
I am trying to write a function which toggles the display of a certain
class of <div> elements in an HTML page. The CSS file initially sets some
classes to "display: none", and...
|
by: Stefan Finzel |
last post by:
Hi,
is there a way to change the display property on Windows Mobile 2003 SE
Mobile/Pocket Internet Explorer? See following example.
Please note: visibilty property has the same problem.
Is...
|
by: Ferry Boender |
last post by:
Hi,
I'm relatively new to Xlib programming, and I ran into a little problem.
I'm trying to insert keypress events into a X window. The following code
works:
...
|
by: Markus Ernst |
last post by:
Hi
When toggling an element on and off by setting its display property via
DOM access, display:none is valid for all kinds of elements, but I can't
find anything about a generic value for...
|
by: RonY |
last post by:
I have a dropdown which calls SetTimePeriod method on change the selection. In the JS function, I reset the field style.display based on what the selection is. This works fine with IE but not working...
|
by: cssExp |
last post by:
hello,
Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |