2

do i need to include something to use time_since() function in php 5 or is has it been replace?

hakre
  • 193,403
  • 52
  • 435
  • 836
Rod Nelson
  • 3,301
  • 5
  • 22
  • 25

2 Answers2

0

It doesn't look like that function ever existed in PHP. Do you mean time() ?

However, you can get the time since an event like so...

$timeSince = time() - strtodate('last Saturday');

You can also use the object DateTime.

$now = new DateTime();

$timeSince = $now->diff(new DateTime('last Saturday'), TRUE);

Note that diff() method wasn't introduced until PHP 5.3.

alex
  • 479,566
  • 201
  • 878
  • 984
  • if i'm using a unix timestamp can that be put in the place if last Saturday in the above? Im looking for an output of 3 days 2 hours 15 mins ago – Rod Nelson Apr 13 '11 at 01:22
  • Nevermind it was a function i wrote and it was hidden inside my include file thx for trying to help! – Rod Nelson Apr 13 '11 at 01:29
0

PHP working out time since the post

If you're using PHP 5.3 or newer, you can take advantage of the new Date and Time classes added to PHP.

Specifically, DateTime has a diff method that returns a DateInterval class, which you can then format.

Community
  • 1
  • 1
Priyank
  • 10,503
  • 2
  • 27
  • 25