I was working on a little attendance tracking system today and I used PHP and some native CodeIgniter functions to get it to play nice with my APP. I’m using one of my favorite new scripts CalendarView to pass the dates into this function from a simple form post.
//Posted values are strings like "2010-01-26"
//Parse dates as unix
$start_date = mysql_to_unix($_POST['start_date']);
$end_date = mysql_to_unix($_POST['end_date']);
//now get the date details
$start_date_array = getdate($start_date);
$end_date_array = getdate($end_date);
//now lets get all the days and get ready to put it in the DB.
for ($i=$start_date; $i <= $end_date; $i = round($i + 86400)) {
$day = getdate($i);
if($day['weekday'] !== 'Saturday' && $day['weekday'] !== 'Sunday'){
$days[$i] = $day;
}
}
print_r($days);
So that's it pretty simple and straight forward. It just returns an array of 'day' data for each day between the 2 posted dates. I have a lot of sanity testing going on etc, but took a while to figure out so I felt like I should post it up and share.
Too often I find a little snippet like this on an obscure site that is the answer to a problem I have been trying to figure out all day. So maybe I can be that helping hand for someone else.






02.19.2010 | 3:22 am
Isn’t that the most amazing experience? So adorable he is. my squishy!