Reputation: 217
How to limit result to today date.
E.g. we have three dates in this format (Y-m-d H:i:s):
$a = "2011-08-10 23:55:01";
$b = "2011-08-10 00:20:01";
$c = "2011-08-10 09:45:01";
and I don't want to echo dates that are past. I want just future dates to be shown.
How to make if then statement for future dates only?
Upvotes: 1
Views: 1009
Reputation: 253318
Because I can't see if you're using this in a function somewhere, I chose to concatenate the dates into an array, and work with the array using a foreach:
$a = "2011-08-10 23:55:01";
$b = "2011-08-10 00:20:01";
$c = "2012-08-10 09:45:01";
$dates = array($a,$b,$c);
echo "<ul>";
foreach($dates as $k => $v) {
if (strtotime($v) > time()){
echo "<li>$v</li>";
}
}
echo "</ul>";
The above, at the time of writing, outputs:
Upvotes: 1