Reputation: 33966
I need to check with php if values got from a database are from last 30 days.
The values are formatted as follows:
2012-03-19 05:00:32
How can this be done?
Upvotes: 0
Views: 718
Reputation: 16462
$date = '2012-03-19 05:00:32';
if (strtotime($date) >= strtotime('-30 days')) {
// do something
}
Upvotes: 1
Reputation: 360742
You could do it in PHP, but that'd mean a roundtrip through the date/time system to process that string back into a date value:
$within_30 = ((strtotime('2012-03-19 05:00:32') + 30*86400) > time());
Assumign you're using MySQL, you could do it in the query directly, and save some time conversions:
SELECT ((yourtimefield + INTERVAL 30 DAY) > now()) AS within_30 ...
Upvotes: 0