Reputation: 3602
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
Reputation: 24645
This should get you there
if( strtotime($row->update_date) > strtotime('-3 days')){
print('true');
}
Upvotes: 5
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