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
Asked
Active
Viewed 242 times
2 Answers
1
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

DiverseAndRemote.com
- 19,314
- 10
- 61
- 70
1
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

Sumit Bijvani
- 8,154
- 17
- 50
- 82