/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] How to: Create A Basic Calendar

I wrote this today, guessed I would share it..

[code=php]
<?php
$year = date(“Y”, time());

for($month = 1; $month <= 12; $month++)
{
?>
<table border=”1″ cellpadding=”2″ cellspacing=”2″>
<tr>
<td colspan=”7″ align=”center”><?php echo date(“F”, mktime(0, 0, 0, $month, 1, $year)); ?></td>
</tr>
<tr>
<td width=”40″ align=”center”>Mon</td>
<td width=”40″ align=”center”>Tue</td>
<td width=”40″ align=”center”>Wed</td>
<td width=”40″ align=”center”>Thu</td>
<td width=”40″ align=”center”>Fri</td>
<td width=”40″ align=”center”>Sat</td>
<td width=”40″ align=”center”>Sun</td>
</tr>
<tr>
<?php
$days_in_the_month = cal_days_in_month(CAL_GREGORIAN, $month, $year);
for($day = 1; $day <= $days_in_the_month; $day++)
{
$day_of_the_week = (int)date(“w”, mktime(0, 0, 0, $month, $day, $year));

if($day == 1)
echo str_repeat(“<td>&nbsp;</td>”, ((($day_of_the_week+7)-1)%7));
?>
<td align=”center”><?php echo $day; ?></td>
<?php

if($day_of_the_week == 0 && $day != $days_in_the_month)
{
?>
</tr><tr>
<?php
}
}
// Finish off by filling in the missing TD’s
echo str_repeat(“<td>&nbsp;</td>”, ((7-$day_of_the_week)%7));
?>
</tr>
</table>
<br>
<br>
<?php
}
?>
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @MrCoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...