0

I am trying to calculate the number of days between 2 dates

Date format is dd/mm/yy

Dates are variable:

$getarrival   = $_GET["arrival"];
$getdeparture = $_GET["departure"];

I tried this but it is not working when you change the date format.

$start = strtotime('2010-01-25');
$end   = strtotime('2010-02-20');

$days_between = ceil(abs($end - $start) / 86400);
powtac
  • 40,542
  • 28
  • 115
  • 170
Antonis Vergetakis
  • 105
  • 1
  • 2
  • 12

1 Answers1

0

As my date format is dd/mm/yyyy I had change format of the date to yyyy/mm/dd and pass it to a new variable

list($arrivalday, $arrivalmonth, $arrivalyear) =explode("/",$getarrival);
list($departureday, $departuremonth, $departureyear) =explode("/",$getdeparture);
$newarrival = ($arrivalyear.'/'.$arrivalmonth.'/'.$arrivalday);
$newdeparture = ($departureyear.'/'.$departuremonth.'/'.$departureday);
$start = strtotime($newarrival);
$end = strtotime($newdeparture);
$totaldays = ceil(abs($end - $start) / 86400);
Antonis Vergetakis
  • 105
  • 1
  • 2
  • 12