Created
March 29, 2018 08:59
-
-
Save Seawed/ac7f29fdcd78705f253c199e418ebe76 to your computer and use it in GitHub Desktop.
simple calendar on PHP(without css and js).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<title> | |
Simple Calendar | |
</title> | |
<?php | |
If (!empty ($_GET['y']) or !empty($_GET['month'])) { | |
$dateYear=$_GET['y']; | |
$nowYear = $_GET['y']; | |
$nowYear2 = $_GET['y']; | |
$nowMonth = $_GET['month']; | |
$daysInMont = date('t', strtotime('01.' . $nowMonth . '.' . $nowYear)); | |
$startDayInMonth = date('N', strtotime('01.' . $nowMonth . '.' . $nowYear)); | |
$monthName = date('F', strtotime('01.' . $nowMonth . '.' . $nowYear)); | |
$countDayInPrevousMonth = date('t', strtotime('01.' . ($nowMonth - 1) . '.' . $nowYear)); | |
if ($startDayInMonth>2){ | |
$needToWriteTd = $startDayInMonth-2; | |
} | |
} else { | |
$dateYear=date('Y'); | |
$nowYear = date('Y'); | |
$nowYear2 = date('Y'); | |
$nowMonth = date('n'); | |
$nowDay = date('j', strtotime('01.' . $nowMonth . '.' . $nowYear)); | |
$monthName = date('F', strtotime('01.' . $nowMonth . '.' . $nowYear)); | |
$daysInMont = date('t',strtotime('01.' . $nowMonth . '.' . $nowYear)); | |
$startDayInMonth = date('N', strtotime('01.' . $nowMonth . '.' . $nowYear)); | |
$countDayInPrevousMonth = date('t', strtotime('01.' . ($nowMonth - 1) . '.' . $nowYear)); | |
if ($startDayInMonth>2){ | |
$needToWriteTd = $startDayInMonth-2; | |
} | |
} | |
$tryDays = 0; | |
$nextDayInNextMonth=1; | |
if ($nowMonth == 1) { | |
$nowYear = $nowYear - 1; | |
} else if ($nowMonth == 12) { | |
$nowYear2 = $nowYear2 + 1; | |
} | |
?> | |
<body> | |
<?php | |
echo $monthName; | |
?> | |
<table> | |
<thead> | |
<tr> | |
<td> Mon </td> | |
<td> Tue </td> | |
<td> Wed </td> | |
<td> Thu </td> | |
<td> Fri </td> | |
<td> Sat </td> | |
<td> Sun </td> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<?php | |
$prevMonthDay = $countDayInPrevousMonth - $needToWriteTd; | |
for (; $prevMonthDay <= $countDayInPrevousMonth; $prevMonthDay++) { | |
echo "<td> | |
<a href='?month=" . ($nowMonth == 1 ? 12 : $nowMonth - 1) . "&y=" | |
.$nowYear . "'>" . $prevMonthDay . "</a> | |
</td>"; | |
$tryDays++; | |
} | |
for ($day = 1; $day <= $daysInMont; $day++) { | |
if(($tryDays + $day)% 7 ==1){ | |
echo'</tr><tr>'; | |
} | |
echo "<td data-year='" . $dateYear . "' data-month='" . $nowMonth . | |
"'><div>$day</div></td>"; | |
} | |
for (;($tryDays + $day) % 7 !==1;$day++){ | |
echo "<td><a href='?month=" . ($nowMonth == 12 ? 1 : | |
$nowMonth | |
+ 1) . "&y=" . | |
$nowYear2 . "'>" . $nextDayInNextMonth . "</a></td>"; | |
$nextDayInNextMonth++; | |
} | |
?> | |
</tr> | |
<tr> | |
<td> Mon </td> | |
<td> Tue </td> | |
<td> Wed </td> | |
<td> Thu </td> | |
<td> Fri </td> | |
<td> Sat </td> | |
<td> Sun </td> | |
</tr> | |
</tbody> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment