zazvorniki
zazvorniki

Reputation: 3602

checking if the date the article was posted is less than three days

I'm trying to write an if statement checking to see if the artical was updated in the last three days so I can feature it. I'm having a bit of trouble finding out just how to do this though. The more I read in articals, the more it strays from what I need.

So far I have been working with this and it seems to pull back everything that was posted before that moment. Some help would be greatly appreciated!

if( strtotime($row->update_date) < strtotime('now')){
    print('true');
}?>

Upvotes: 0

Views: 250

Answers (2)

Orangepill
Orangepill

Reputation: 24645

This should get you there

if( strtotime($row->update_date) > strtotime('-3 days')){
    print('true');
}

Upvotes: 5

Ja͢ck
Ja͢ck

Reputation: 173562

You can add a column using SQL as well, assuming MySQL:

SELECT ..., update_date > DATE_SUB(NOW(), INTERVAL 3 DAYS) AS less_than_three_days_ago

Then, in PHP:

if ($row->less_than_three_days_ago) {
    print 'true';
}

Upvotes: 0

Related Questions