php question… how to check if something is between two values?

后端 未结 5 1853
你的背包
你的背包 2021-01-23 08:40

I know I\'m missing something easy here... I\'ve been trying different operators, but haven\'t been able to figure this out...

How do I go about checking to see if the

相关标签:
5条回答
  • 2021-01-23 08:58

    the googles told me

    if ( strtotime($date) > strtotime('22/09/2008') && strtotime($date) < strtotime('28/09/2008'))
    

    http://answers.yahoo.com/question/index?qid=20081003113922AAHnQsp

    0 讨论(0)
  • 2021-01-23 09:03

    To do a comparison like this you need to do separate comparisons. If $d is the date you want to compare, $d1 is the earlier date, and $d2 is the later date, it would be something like:

    if ((strtotime($d) > strtotime($d1)) and (strtotime($d) < strtotime($d2))) {
        return true;
    } else {
        return false;
    }
    
    0 讨论(0)
  • 2021-01-23 09:05

    wouldn't this work ?

     ( ($lowerlimitdate <= $checkingdate) && ($checkingdate <= $upperlimitdate))
    
    0 讨论(0)
  • 2021-01-23 09:12

    If past date one and before date two, then it's between them.

    0 讨论(0)
  • 2021-01-23 09:18

    Off the top of my head, I don't know of a date comparison operator in PHP, but I would use strtotime() on all three dates, then do simple mathematical comparisons.

    <?php
    
    $early_date = strtotime("02/02/2010");
    $date = strtotime("02/04/2010");
    $late_date = strtotime("02/10/2010");
    
    if (($early_date < $date) && ($date < $late_date)) {
      echo "true";
    }
    

    returns true.

    0 讨论(0)
提交回复
热议问题