-5

Possible Duplicate:
How to calculate the difference between two dates using PHP?

I have three input in html. two of them are start date and end date and the third one is to find the difference between them and display the result .

here is the inputs:

<p><span>Start date:</span> <input type="date" required min="2012-01-01" name="start_d" id="start_d" ><span>* Format: YYYY-MM-DD</span><br></p>
<p><span>End date:</span> <input type="date" required min="2012-01-01" name="end_d" id="end_d" ><span>* Format: YYYY-MM-DD</span><br></p>
<p><span>Duration :</span><input type="text" required name="duration" id=duration" readonly="readonly"><br></p>
Community
  • 1
  • 1

3 Answers3

1
$date1 = new DateTime("2011-02-01");
$date2 = new DateTime("2012-01-01");
$duration = $date1->diff($date2);
var_dump($duration);
Valeh Hajiyev
  • 3,216
  • 4
  • 19
  • 28
0
date('Y-m-d', (strtotime($str_start_date) + round((strtotime($str_end_date) - strtotime($str_start_date)) / 2))';

EDIT:

Missunderstood your question. Though you wanted the date between these? You want the difference in seconds?

round((strtotime($str_end_date) - strtotime($str_start_date)) / 2)
Robin Castlin
  • 10,956
  • 1
  • 28
  • 44
0

Take a look at http://php.net/manual/en/function.date-diff.php and How to calculate the difference between two dates using PHP?

Community
  • 1
  • 1
Mohammad Saberi
  • 12,864
  • 27
  • 75
  • 127