Can anyone correct the error in my script to calculate the number of days between 2 dates. The dates have been input through a form, the variable info is as followed:
The easiest way is by using datetimes.
Consider this:
var_dump(new DateTime('1 July 2007'));
$a = new DateTime('1 July 2007');
$b = new DateTime('1 June 2001');
var_dump($a->diff($b));
The var_dump will allow you to see the different kind of time you can extract from it.
object(DateInterval)[3] public 'y' => int 6 public 'm' => int 1 public 'd' => int 0 public 'h' => int 0 public 'i' => int 0 public 's' => int 0 public 'invert' => int 1 public 'days' => int 2221
You can convert your array to a date time very easily by using
$date = new DateTime(join(" ",$array));
$date2 = new DateTime(join(" ",$array2));
$diff = $date->diff($date2);