问题
I have a list of dates and need to enforce a limit, which is the list to not be older than today but more than 30 days ahead of today.
Is possible to modify what I have or do I need to use something like 'time' instead? if so how would I adjust what I have?
$date = new DateTime($page->meta_value);
if (strtotime($page->meta_value) > time()) {
echo '<h2><div class="date-title">';
echo $page->post_title.' - ';
echo '</div><div class="date-date">';
echo $date->format('d-m-Y').'<br/>';
echo '</div></h2>';
}
Thanks for reading :)
回答1:
Try this:
if (strtotime($page->meta_value) >= time() && strtotime($page->meta_value) < strtotime('+30 days')) {
Or up to this month only?
if (strtotime($page->meta_value) >= time() && strtotime($page->meta_value) < strtotime('first day of next month')) {
回答2:
Things that can help you:
print date('Y-m-d',strtotime('last day of this month'));
http://php.net/manual/en/datetime.formats.relative.php
print date('Y-m-d',strtotime('+ 30 days'));
http://php.net/manual/en/datetime.formats.date.php
Read more here http://php.net/manual/en/datetime.formats.php
来源:https://stackoverflow.com/questions/41445960/php-check-if-date-is-today-or-greater-but-only-in-this-month