PHP date diff
I call out for an excuse for not practicing PHP enough recent year; with just a simple date_diff could knock me out :) not to open my complain of having different version of PHP to check before using a function(s) I got a request from a friend to help workout how many days from two given date.
Now if I have two date string (it is what we get from form post right?)
// fixed format as I don't want to deal with complicate of different world format :( $day1 = "26/03/2009"; $day2 = "28/03/2009"; // now I need to know how many days does it take from day1 to day2 // PHP 4.x; ignore my out of date PHP skill this is how I did it $break_day1_apart = explode('/', $day1); $break_day2_apart = explode('/', $day2); $day1_number_form = $break_day1_apart.$break_day1_apart.$break_day1_apart; $day2_number_form = $break_day2_apart.$break_day2_apart.$break_day2_apart; $day_diff = abs((int)$day2_number_form - (int)$day1_number_form); // and it should work by theory echo $day_diff;
Suck ! what would you do instead?