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?
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?
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)
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).