You are currently browsing the Mutant Squirrel posts tagged: calendar

Dead Simple PHP Calendar

I needed a calendar for a PHP project I was working on. I did a quick look around and found some promising solutions, but they all seemed way more complex than what I wanted. They also used tables, which are gross. This is a ridiculously easy way to get a calendar from php:function calendar($date=false){ $date_parts=(!$date)?preg_split("/[-]+/",$date):preg_split("/[-]+/",date('Y-m-d')); $year=$date_parts[0];$month=$date_parts[1];$day=$date_parts[2]; $time=mktime(0,0,0,$month,1,$year); $month_name=date('F',$time); $days_in_month=cal_days_in_month(CAL_GREGORIAN,$month,$year); $first_day=date('w',$time); $calendar=''.$month_name.' Read more [...]