Reputation: 205
I would like to count the date difference which the user select from the datepicker through $_POST
. Both $from
and $to
returns date picked by the user from the form but the date_diff
and other user's method wouldn't work, thus posting this. I am only interested in the date, so time is not important for me.
This is my code:
$from = $_POST['dateFrom'];
$to = $_POST['dateTo'];
echo $from;
echo $to;
$newFrom = strtotime($from);
$newFormatFrom = date('m-d-Y',$newFrom);
$newTo = strtotime($to);
$newFormatTo = date('m-d-Y',$newTo);
$dateDiff = date_diff($newFormatFrom, $newFormatTo);
Upvotes: 2
Views: 160
Reputation: 11987
<?php
$from = strtotime($_POST['dateFrom']);
$to = strtotime($_POST['dateTo']);
$datediff = $to - $from;
echo floor($datediff/(60*60*24));
?>
Upvotes: 1
Reputation: 1862
$noofdays = (strtotime($to)-strtotime($from))/(60*60*24);
print $noofdays;
Upvotes: 1
Reputation: 154
use date_create function, may be this will help you:
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
Upvotes: 0