-6

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

I have two time in this format: date("Y-m-d H:i:s"). How can I calculate different between these two time?

Community
  • 1
  • 1
Ehsan
  • 2,273
  • 8
  • 36
  • 70

2 Answers2

1

Use the DateTime class and the diff method.

Daniel Ribeiro
  • 10,156
  • 12
  • 47
  • 79
1

Try this:

<?php
    $datetime1 = date_create($start);
    $datetime2 = date_create($end);
    $interval = date_diff($datetime1, $datetime2);
    return $interval->format('%a'); //returns the number of days
?>
Ignas
  • 1,965
  • 2
  • 17
  • 44