Rufus_84 Posted December 15, 2012 Share Posted December 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/272038-date-difference-of-the-dates-taken-from-datepicker/ Share on other sites More sharing options...
Barand Posted December 15, 2012 Share Posted December 15, 2012 We are nor clairvoyant nor can we look over your shoulder to see what you are seeing. When you echo $dat1 and $dat2 what does it give? Quote Link to comment https://forums.phpfreaks.com/topic/272038-date-difference-of-the-dates-taken-from-datepicker/#findComment-1399604 Share on other sites More sharing options...
silkfire Posted December 15, 2012 Share Posted December 15, 2012 var_dump the variables $dat1 and $dat2 and see what you get back. Quote Link to comment https://forums.phpfreaks.com/topic/272038-date-difference-of-the-dates-taken-from-datepicker/#findComment-1399605 Share on other sites More sharing options...
Barand Posted December 15, 2012 Share Posted December 15, 2012 OK Rufus, Silkfire will take over from here. Quote Link to comment https://forums.phpfreaks.com/topic/272038-date-difference-of-the-dates-taken-from-datepicker/#findComment-1399606 Share on other sites More sharing options...
Rufus_84 Posted December 16, 2012 Author Share Posted December 16, 2012 when i echo $dat1 and dat2 i get nothing- blank page. Anyway I resolved the problem. All i had to do was change the jQuery output date format to yy-mm-dd. :-) Quote Link to comment https://forums.phpfreaks.com/topic/272038-date-difference-of-the-dates-taken-from-datepicker/#findComment-1399608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.