Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.