1

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');        
RicardO
  • 1,219
  • 1
  • 14
  • 24

1 Answers1

4

There isn't a built-in equivalent for date->diff in 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.

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • 1
    I'd like to upgrade but my hosting is no will not be able to do that for me. because we are on a shared hosting.. – RicardO Jul 12 '11 at 10:54
  • @ricky - you should ask your hosting company why they're willing to run un-supported software on their servers. It's been several months now since support was ended for 5.2, and *years* since 5.3 was introduced. They've had plenty of time to upgrade. – Spudley Jul 12 '11 at 10:56
  • yeah I had ask that question to them, still waiting for a reply. – RicardO Jul 12 '11 at 11:03