I have this code in php that I could not run in PHP 5.2.9
please give me an Idea to convert this code to work on PHP 5.2.9
Thanks,
$startTime = new DateTime(date('h:i:s a'));
$endTime = new DateTime("3:00:00 pm");
$timeTaken = $endTime->diff($startTime);
$timeTaken = $timeTaken->format('%h hour, %i mins, %s sec');
There isn’t a built-in equivalent for
date->diffin PHP 5.2, so you’ll have to write your own.Fortunately, the PHP manual has comments where people have done the hard work for you.
See http://php.net/manual/en/function.date-diff.php, scroll down to the comments, and pick your favourite solution (there are several to choose from).
The other solution is simply to bite the bullet and upgrade — PHP 5.2 is no longer supported, so you really should be considering upgrading.