views:

71

answers:

2

Hey guys, i'm using this script (http://snipplr.com/view/4912/relative-time/) to create relative times using PHP and timestamps stored in my database. I'm using the standard format for storing datetime (eg 2010-05-07 20:26:17) and it works fine with any timestamps i create.

But for some reason when i try to use a timestamp stored in wordpress's wp_posts table, the function fails and returns "January 1, 1970". I can't see any difference in the format of wordpress' timestamps and my own. And i can use wordpress' data fine using the date() function to present a formatted date, just not a relative time using my own function.

A: 

If you can use the dates fine with date() then you probably have them in UNIX timestamp format already. Try removing the strtotime() calls in getRelativeTime() (on line 7 and 22).

Emil Vikström
A: 

You don't need that script - WordPress has a human time difference function you can use

To print an entry's time ("2 days ago"):

<?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>

For comments:

 <?php echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; ?> 
Jared