473,503 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sample month at a time code for events calendar

I am in the process of rewriting one of my first PHP scripts, an event
calendar, and wanted to share the code that is the core of the new
calendar. My current/previous calendar processed data dates only, this
code is intended to use more thrifty event descriptions (3rd saturday,
last tuesday, etc.) as well as traditional one-of dates.

The core here here is quite spartan, no table logic or or db cruft
included (I figure you have our own design ideas/preferences.)

Enjoy
Larry

<?php
//sample code to generate american calendar format for a given month
// i,e. start of sunday on or before the 1st end on te saturday on or
after the last day.
// makes use of mktime's cool liberal calculation of dates.

// Set sample month and year values:
$mn = date("m");
$yr = date("Y");

// Start calendar logic:

$firstday = date("w",mktime(0,0,0,$mn,1,$yr)); // Get first day of
target month (0=sum 6=set)

$numdays = date("t",mktime(0,0,0,$mn,1,$yr)); // Number of days in
target month

$daystop = $numdays+(6-date("w",mktime(0,0,0,$mn+1,0,$yr))); //
Adjusted last saturday of calendar page (on or after last day of month

//start with american first sunday on or before start of month of
calendar page and end on daystop (saturday)
for($daynum = 1 - $firstday; $daynum <= $daystop; $daynum++) {

//need working date timestamp to work out details of the calendar
$wkdate = mktime(0,0,0,$mn,$daynum,$yr); //the first of the month -
unix value

$wdy = date("w",$wkdate); //day of the week (0 sun - 6 sat)
$wmn = date("m",$wkdate); //month
$wdt = date("d",$wkdate); //date

$wdte = date("D, m/d/Y",$wkdate); //date string of current date "Day,
mm/dd/yyyy"

$ndays = date("t",$wkdate); //# days in working month
$wknum = intval(($wdt-1) / 7)+1; //week number in month

$lastweek = ($wdt $ndays-7 ? true : false); //last week of month

$curmonth = ($wmn == $mn ? true : false); //current month (for
coloring)

// display example of what we know:
echo (($wdy % 6)==0 ? "*": ""). //indicate if date is a weekend date
"Date: ".$wdte. //day of week and date
", Week: ".$wknum. //indicate if it is the last week of the month
($lastweek==true? " (last)" : "")."<br />";
if ($wdy == 6) { // divide between american weeks sun-sat (new
row/line)
echo "<hr />";
}
}
?>

Dec 17 '06 #1
0 1886

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
2351
by: pb648174 | last post by:
Greeting, below is the complete SQL taken from aspfaq.com (retrieved from this newsgroup I believe) The query takes about two minutes to run. Does anybody have a better set based way (sub-second...
2
6963
by: bb | last post by:
any way to prevent displaying the previous and next months in the calendar control? i have tried just blanking the text out in the dayrender IsOtherMonth and also dynamically changing the...
34
9250
by: prosoft | last post by:
When I use Dim myDTFI As DateTimeFormatInfo = New CultureInfo("he-IL", True).DateTimeFormat Dim strhmon1 As String = (myDTFI.GetMonthName(hmon1)) MsgBox(strhmon1) I get the local name of the...
4
6675
by: Jason Chan | last post by:
How can I get the month and year a calendar control current displaying? My problem is I want to load a list of event to a calendar so that it display difference style if there a event for a day....
5
2452
by: tolcis | last post by:
Hi! I have a query that has to return bunch of data based on the calendar month. I have to make sure that it will return data to me for 28 days if it is February and for 31 if it is August(for...
6
3257
by: Zeba | last post by:
Hi, I have a page with a calendar and two datalist items - one containing month values and the other, year values. Depending on the month/year value chosen ( in text/string format ) I should be...
7
3810
by: ajaydesai | last post by:
I have JavaScript code to dispaly two month calendar days at a time, but i have a problem both month that disaplay at a time have same days (for example May and June has same days, June and July have...
11
7353
by: Randy | last post by:
I have a MonthCalendar on one of my forms. I have disovered that the DateChanged event is triggered not only when the user clicks on a new date, but also if they click on the Previous or Next...
3
1239
by: Droopy | last post by:
Hi, Iam using a MonthCalendar.I have hosted this in a popup control.On click of an image,i get my month calendar(i.e. the popup) displayed.Once i choose the date ,the selected date gets populated...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
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...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7319
jinu1996
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...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
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...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.