I've one mysql table in that I store two dates say 2015-03-13 and 2015-03-20 and I displays these dates on form with no. of days between these two dates.
In this I want PHP code for calculating days.
I've one mysql table in that I store two dates say 2015-03-13 and 2015-03-20 and I displays these dates on form with no. of days between these two dates.
In this I want PHP code for calculating days.
Try with this (Object oriented style):
<?php
$datetime1 = new DateTime('2015-03-13');
$datetime2 = new DateTime('2015-03-20');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a días');
?>
Procedural Style:
<?php
$datetime1 = date_create('2009-10-11');
$datetime2 = date_create('2009-10-13');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%a días');
?>
You can read more at:
$start = strtotime('2015-03-13');
$end = strtotime('2015-03-20');
$diff = $end - $start;
$days = floor($diff / (3600 * 24));
Try This.
$date1=date_create("2013-03-15");<br>
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2); <br>
echo $diff->format("%R%a days");
Source: http://www.w3schools.com/php/showphp.asp?filename=demo_func_date_diff
Try this code:
<?php
$first_date = strtotime("2015-03-10");
$last_date = strtotime("2015-03-01");
$datediff = $first_date - $last_date;
echo "Days : ". floor($datediff/(60*60*24));
?>
Use this
$daylen = 60*60*24;
$date1 = '2015-03-13';
$date2 = '2015-03-20';
echo (strtotime($date1)-strtotime($date2))/$daylen;