Answers for "if datetime is in range php"

PHP
1

check if date is within range php

$start_date = '2020-10-21';
$end_date = '2020-10-15';
$date_check = '2020-08-28';

if ($this->check_in_range($start_date, $end_date, $date_from_user)) {
  echo "within range";
} else {
  echo "not within range";
}

function check_in_range($start_date, $end_date, $date_from_user) {
  // Convert to timestamp
  $start = strtotime($start_date);
  $end = strtotime($end_date);
  $check = strtotime($date_from_user);

  // Check that user date is between start & end
  return (($start <= $check ) && ($check <= $end));
}
Posted by: Guest on October-21-2020

Browse Popular Code Answers by Language