This question already has an answer here:
Hello and thanks for the help. I have a table in mysql with 2 columns (date1),(date2).I want to find the days between these two days and calculate a price of 10 dollars for each day through php
</div>
here you go:
$dt1 = new DateTime("@{$date1}");
$dt2 = new DateTime("@{$date2}");
$interval = $dt1->diff($dt2);
$price = 10 * $interval->d;
This assumes that you are saving your dates $date1
and $date2
as unix timestamps
Try this..
<?php
$first_date = strtotime("2013-04-10");
$last_date = strtotime("2013-04-01");
$datediff = $first_date - $last_date;
echo "Days : ". floor($datediff/(60*60*24))."<br>";
echo "Price : $". (floor($datediff/(60*60*24)))*10;
?>
Output
Days : 9
Price : $90