1

My host makes working with MySQL exceedingly difficult; to avoid having to work with MySQL, is there any way to add timestamps to articles by using a table-less "time ago" function, then using echo to display the difference between the current date and the "time ago" date?

1 Answer 1

2

Add a DATETIME column to your article table. Then when you insert/update an article you can set the time with

$row = array(
    'title' => 'My Article',
    ...
    'date' => date("Y-m-d H:i:s")
);

$db->insert('article', $row);

When you pull the article out you can get the difference:

$row = $db->get('article', 32);

$diff = time() - strtotime($row['date']); 

print $diff . ' in seconds';

You can then do something with the seconds $diff like divide by minutes, hours, days, etc.. to show the type of time ago you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.