Difference between two dates in days, hours & minutes

4 posts by 3 authors in: Forums > CMS Builder Community
Last Post: May 15, 2015   (RSS)

By Ryan - March 25, 2015 - edited: March 27, 2015

 $openDate = strtotime($record['createdDate']);
 $closeDate = strtotime($record['closedDate']);
 $dateDiff = ($closeDate - $openDate);
  $d = ($dateDiff/(60*60*24))%365;
  $h = ($dateDiff/(60*60))%24;
  $m = ($dateDiff/60)%60;
  echo $d." days\n";
  echo $h." hours\n";
  echo $m." minutes\n";

By Damon - March 26, 2015

Nice one!

Note: I had to change $RECORD to $record to get it to work with my local WAMP server.

Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.

By Ryan - March 27, 2015

Thanks Dave, I've updated my original post to reflect the changes.  

By gkornbluth - May 15, 2015

Hi mjftech,

Great post.

Thanks for taking the time to share.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php