-5

Possible Duplicate:
PHP: producing relative date/time from timestamps

Pretty much as the title says, would be perfect for my website and have looked on google with no luck. Anyone have any idea how i could make/find one?

Community
  • 1
  • 1
user1527354
  • 195
  • 2
  • 11
  • Just deduct -43 from current time(), or -86400 for a day. – Shai Mishali Sep 10 '12 at 15:15
  • Did you try writing any code? this should be pretty straightforward. There's also a lot of questions about this already, many which don't match exactly but may be of use anyway. [This](http://stackoverflow.com/questions/1344852/can-my-php-time-difference-function-be-improved) for example. – Emil Vikström Sep 10 '12 at 15:15
  • @EmilVikström Neither produce the desired output. – user1527354 Sep 10 '12 at 15:19

2 Answers2

0

google (time ago php) gave me this: http://css-tricks.com/snippets/php/time-ago-function/

Looks plain simple but solid to me (not tested)

Najzero
  • 3,164
  • 18
  • 18
0

You can do this easily with some basic math. Find the difference between time() and your timestamp. One year is 60 * 60 * 24 * 365; one month is 60 * 60 * 24 * 30; one day is 60 * 60 * 24; one hour is 60 * 60; one minute is 60.

Just find out how many years you have, and subtract them out of the total and store them in a variable.

Then find out how many months you have, and subtract them out of the total and store them in a variable.

Then find out how many days you have, and subtract them out of the total and store them in a variable.

Then find out how many hours you have, and subtract them out of the total and store them in a variable.

Then find out how many minutes you have, and subtract them out of the total and store them in a variable.

The remainder is how many seconds you have; store them in a variable.

Then print out the desired string, using all of those variables, or if it's in a function or class method, just return that string (or, better yet, an array that contains the years, months, days, hours, minutes, and seconds).

TonyTheJet
  • 517
  • 1
  • 6
  • 15