php check if date is today or greater. but only in this month

对着背影说爱祢 提交于 2019-12-25 04:57:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!