Php > Date Time sample source codes
Dynamic Calendar (easiest ever)
Dynamic Calendar (easiest ever) ## change to the previous month if ($command == "prev_month") { if (--$month == 0) { $month = 12; $year--; } } ## change to the next month else if ($command == "next_month") { if (++$month == 13) { $month = 1; $year++; } } ## if no month has been passed if ($month == "") { $year= date("Y"); $month= date("n"); $month_name = date("F",mktime(0,0,0,$month,1,$year)); } ## use current date if no month is passed else { $year= date("Y",mktime(0,0,0,$month,1,$year)); $month= date("n",mktime(0,0,0,$month,1,$year)); $month_name = date("F",mktime(0,0,0,$month,1,$year)); } $dow = date("w",mktime(0,0,0,$month,1,$year)); //which day 1 falls on in the week (0 = Sun) $dim = date("d",mktime (0,0,0,$month+1,0,$year)); //days in the current month ## modification to only print the number of weeks in a month $wim = ceil(($dim+$dow)/7); //weeks in month $ct=0; echo "
<<
$month_name $year
>>
Sun
Mon
Tue
Wed
Thu
Fri
Sat
"; ## print only the number of weeks needed for($row=1;$row<$wim+1;$row++) { echo "
"; ## prints week (Sun to Sat) for($week=1;$week<8;$week++) { $ct++; $value=mktime(0,0,0,$month,$ct-$dow,$year); ## if $value is part of current month if (date("m",$value)==$month) { echo "
".date("j",$value)."
"; } ## print previous and next month dates, but grayed out else { echo "
".date("j",$value)."
"; } } echo "
"; } echo "
"; ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage