1. ## Date intervals!

OK, so I have a 'latest posts' script which basically gets the last 3 posted blogs on my site.

So, for example it would show:

My Last Blog
By: Sean
Sat, 17th Feb 07

However, I wish to show how long ago the blog was actually posted. Therefore instead of showing 'Sat, 17th Feb 07' it would return '6 mins ago' or '2 days, 15 mins ago'...you get the idea.

2. Get todays date, and compare it with the date of the posting. You may have to convert it all into a numeral value and subtract then convert back to a readable date.

Take a look at the date() and strtotime() functions.

Hope that helps

3. Not really haha. I know how to do that.

Cheers anyways

4. I use this function for showing something's age. Definitely not the smartest code but hey it works.
PHP Code:
``` function showSmartDate(\$date,\$date2 = NULL) { /* ** */     \$sec = 1;     \$min = 60;     \$hour = 60 * 60;     \$day = 60*60*24;     \$week = \$day * 7;     \$month = \$day * 30;     \$year = \$month * 12;     if (\$date2 == NULL)         \$date2 = time();     \$diff = abs(\$date2 - \$date);     if ((\$diff > (2 * \$year)) && (\$diff > (6 * \$month))) {         \$output = round((\$diff / \$year),0)." years ago";     }     elseif ((\$diff > \$month) && (\$diff > (6 * \$week))) {         \$output = round((\$diff / \$month),0)." months ago";     }     elseif ((\$diff > \$week) && (\$diff > (10 * \$day))) {         \$output = round((\$diff / \$week),0)." weeks ago";     }     elseif ((\$diff > \$day) && (\$diff > (36 * \$hour))) {         \$output = round((\$diff / \$day),0)." days ago";     }     elseif ((\$diff > \$hour) && (\$diff > (90 * \$min))) {         \$output = round((\$diff / \$hour),0)." hours ago";     }     elseif ((\$diff > \$min) && (\$diff > (90 * \$sec))) {         \$output = round((\$diff / \$min),0)." minutes ago";     }     else {         \$output = \$diff." seconds ago";     }     return \$output; }  ```

5. Ace man, I'll give it a go, cheers!

6. Umm Great function! mcmunt. The function works me fine but i am not sure about backtobasics.

7. Do it all in SQL, rplace date1 with the last posting time

Code:
```
SELECT CONCAT(DAYOFYEAR(date1)-DAYOFYEAR(NOW()),' days ', DATE_FORMAT(ADDTIME("2000-00-00 00:00:00",SEC_TO_TIME(TIME_TO_SEC(date1)-TIME_TO_SEC(NOW()))),'&#37;k hours and %i minutes')) AS time FROM time_table;```

8. Originally Posted by mcmunt
I use this function for showing something's age. Definitely not the smartest code but hey it works.
PHP Code:
``` function showSmartDate(\$date,\$date2 = NULL) {     //...     \$month = \$day * 30;     \$year = \$month * 12;     //... }  ```
Are those interval definitions a little... vague?

9. You might find this code useful --> http://code-bin.homedns.org/13

I'm not sure how your data input is formatted, but you could use substr() to grab the values for \$h1, \$m1, \$s1, \$m1, \$d1, and \$y1.

Example output: 7 days 3 hours 42 minutes 2 seconds

If you just needed the value of days, http://code-bin.homedns.org/8 would work for ya'.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•