PHP Calendar Script

PHP Calendar Script

Sharing is caring!

This calendar script developed with PHP5 and you can customize the year you need.

CSS PART
{code type=css}
table{
float:left;
height:250px;
font-size:12px;
font-family: Tahoma, Arial, sans-serif;
border-collapse:separate;
empty-cells:hide;
}

div#sample{
height:200px;
}

.find{
color:#FFFFFF;
background:#FF0000;
}

{/code}

PHP part
{code type=php}

$find_dt=’1991-11-01′;

for($i=1;$i<=12;$i++){
//calen(1984,$i);
calen(1991,$i,$find_dt);
if($i==6){
echo ”

“;
}
}

//version#1
function calen1($start,$div){
echo ‘

‘; for($i=1;$i<=31;$i++){ $j=$i%7; if($j==’1’){ echo ”; } echo ”;
}
echo ‘

‘.$i.’:’.$j.’

‘;
}
//version#2
function calen2($start){
echo ‘

‘; for($k=1;$k<=$start;$k++){ echo ”;
}
$div=8-$start;
for($i=1;$i<=31;$i++){
$j=$i%7;
if($j==$div){
echo ”; } echo ”;
}
echo ‘

‘.$i.’:’.$j.’

‘;
}

//final
function calen($year,$month, $find_dt){

$find=0;

//find no.of days
$last = cal_days_in_month(CAL_GREGORIAN, $month, $year);

//find start value
//$cur_1st=date(“$year-$month-01″);
//$day=date(‘w’,strtotime($cur_1st));

//$d = new DateTime(‘2010-01-19′);
$d = new DateTime(”.$year.’-‘.$month.’-01′);
//$d->modify(‘first day of this month’);
$day=$d->format(‘w, F Y’);
//echo $day;
$start=$day+1;

if(date(‘m’,strtotime($find_dt))==$month AND date(‘Y’,strtotime($find_dt))==$year){
$find=1;
}

//echo $start;
//set breakpoint
$div=array(“1″=>”1″,”2″=>”0″,”3″=>”6″,”4″=>”5″,”5″=>”4″,”6″=>”3″,”7″=>”2″,”8″=>”1”);

$mons = array(1 => “Jan”, 2 => “Feb”, 3 => “Mar”, 4 => “Apr”, 5 => “May”, 6 => “Jun”, 7 => “Jul”, 8 => “Aug”, 9 => “Sep”, 10 => “Oct”, 11 => “Nov”, 12 => “Dec”);

echo ‘

‘;for($k=1;$k<$start;$k++){
echo ‘ ‘;
}for($i=1;$i<=$last;$i++){
$j=$i%7;
if($j==$div[$start]){
echo ”; } if($find==1 AND date(‘d’,strtotime($find_dt))==$i){ echo ”;
}
else{
echo ‘
‘.$i.”;
}
}
echo ‘

‘.$mons[$month].’ ‘.$year.’
Sun Mon Tue Wed Thu Fri Sat
‘.$i.’

‘;
}

{/code}

Demo Link

Sharing is caring!

Comments are closed.