Skip to content

Instantly share code, notes, and snippets.

@riaf riaf/gist:863507
Created Mar 10, 2011

Embed
What would you like to do?
カレンダーっぽい感じのあれ
<?php
function getCalendar($date) {
if ($date instanceof DateTime === false) {
$date = new DateTime($date);
}
$sdate = clone $date;
$sdate->modify('first day of');
$edate = clone $sdate;
$edate->modify('+1 month');
if ($sdate->format('w')) {
$sdate->modify('last sunday');
}
if ($edate->format('w')) {
$edate->modify('next sunday');
}
$period = new DatePeriod(
$sdate,
new DateInterval('P1D'),
$edate
);
return $period;
}
foreach (getCalendar(new DateTime('+1 month')) as $k => $d) {
if ($k !== 0 && $k % 7 === 0) {
echo PHP_EOL;
}
echo $d->format("\td");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.