0

How to Calculate time difference between two dates in php?

$date1=date('Y-m-d H:i:s');
$date2=date('2015-03-06 45:06:03');(Db)

am trying to do once time difference between 2 hours send Mail to user.Current datetime and Db datetime difference between 2 hours mean Send Mail to user.How to Check?

kavi ck
  • 117
  • 1
  • 10

2 Answers2

0

Did you try $diff=$date1 - $dates?

HasanCseBuet
  • 108
  • 3
  • 13
0

strtotime — Parse about any English textual datetime description into a Unix timestamp and divide by 3600 to find result in hours. Try like this..

$date1=date('Y-m-d H:i:s');
$date2=date('2015-03-06 45:06:03');
echo $diff_hours = (strtotime($date1) - strtotime($date2))/3600;
Amit Rajput
  • 2,061
  • 1
  • 9
  • 27