Jump to content

Date Difference Of The Dates Taken From Datepicker


Rufus_84

Recommended Posts

Hello.

I'm new to php and I've been working on calculating the difference of two dates picked by using a jQuery datepicker and i cannot get it work.

My code is:

 

$date1 = ($_POST['date1']);

$date2 = ($_POST['date2']);

 

$hour1 = ($_POST['hour1']);

$hour2 = ($_POST['hour2']);

 

$min1 = ($_POST['min1']);

$min2 = ($_POST['min2']);

 

 

$dat1 = $date1." ".$hour1.":".$min1;

$dat2 = $date2." ".$hour2.":".$min2;

 

$start = strtotime($dat1));

$end = strtotime($dat2));

 

$date_diff = $end - $start;

 

$days = ceil($date_diff/3600/24);

 

echo $days

 

The code seems to be correct, because when I'm not using the datepicker, but typing the dates in manually it shows the number of days. However when I use the datepicker it posts the dates which I checked by adding "echo $dat1 and echo $dat2" but it's not showing the amount of days at all.

 

I'd really appreciate if anyone could help me with this.

 

Thanks a lot.

 

Raf

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.