0

I'm getting this kind of error I can't find the same question is this new. I'm using PHP7 I doubt that is on memory_limit but my I already changed it to 1024M. I'm trying to determine whether is date is in between of two dates. Is there any way or how can I resolve this issue.

function isBetween ($from, $to, $input){
    $input = (is_int($input) ? $input : strtotime($input));
    $from = (is_int($from) ? $from : strtotime($from));
    $to = (is_int($to) ? $to : strtotime($to));

    if(in_array($input, range($from,$to)) ){
        return 1;        
    }
    return 0;
}
Naib Sorion
  • 474
  • 1
  • 7
  • 17
  • 2
    `$input >= $from && $input <= $to`? – tkausl Oct 23 '17 at 06:38
  • That one is good thanks but hope that to know what does error mean – Naib Sorion Oct 23 '17 at 06:46
  • Possible duplicate of [php question... how to check if something is between two values?](https://stackoverflow.com/questions/2204725/php-question-how-to-check-if-something-is-between-two-values) and https://stackoverflow.com/questions/26999831/check-if-todays-date-is-between-two-other-dates and https://stackoverflow.com/questions/19070116/php-check-if-date-between-two-dates – mickmackusa Oct 23 '17 at 07:56

2 Answers2

1

You dont need to create such a huge array, just to check if a date is between two others. All you have to do (if you dont have your date already in unit timestamp format), is convert all dates to unix timestamps and do a simple if:

if ($startTimestamp < $input && $input < $to) {
    print 'Yay!';
}
Manuel Mannhardt
  • 2,191
  • 1
  • 17
  • 23
1

I would do as tkausl says:

function isBetween ($from, $to, $input){
    $input = (is_int($input) ? $input : strtotime($input));
    $from = (is_int($from) ? $from : strtotime($from));
    $to = (is_int($to) ? $to : strtotime($to));
    return ($input>=$from && $input<=$to)?1:0;  // this is "inclusive" of the start and end
}

For information about array limitations, you can start your research journey here:

mickmackusa
  • 43,625
  • 12
  • 83
  • 136