APPLY FOR ONLINE Zend Framework Certification

                    
                        Here we are Discussing about  finding Difference Between 
  Two dates

  $date1 = "2014-05-27 01:00:00";
  $date2 = "2014-05-28 02:00:00";
  $timestamp1 = strtotime($date1);
  $timestamp2 = strtotime($date2);
  echo "Difference between two dates is " . 
  $hour = abs($timestamp2 - $timestamp1)/(60*60) . " hour(s)";

If you want to calculate the difference from Todays date
  Then you have to use
  $date1 = "2014-05-27 01:00:00";
  $date2 = date('Y-m-d H:i:s');
  $timestamp1 = strtotime($date1);
  $timestamp2 = strtotime($date2);
  $hour = abs($timestamp2 - $timestamp1)/(60*60*24); 
  // will reflect Days                    
                


Comment


Back to Top