0

I used this condition to check if a user enters a valid date or not. When testing, I can enter this date [2020-99-99] and it will pass with no errors.

This throws an error in the file C:\Program Files\JetBrains\PhpStorm 2019.3.4\plugins\php\lib\php.jar!\stubs\date\date_c.php source root: date_c.php


switch ($option->option_en) {
            case 'date':
                if (\DateTime::createFromFormat('Y-m-d', $dataTypeValue) !== FALSE) {
                    return true;
                }
                $this->message = "You should enter valid " . $option->option_en;
                break;
defaut:
return false;
break;
}```
petersowah
  • 728
  • 8
  • 20
  • This has an inbuilt “magic” to convert this into a date, by applying the excess as if months and days got added. If you actually look at the result of this, you will see that it has created a date object for `2028-06-07` based on this. So the solution is simple - you format the resulting date you get _as_ `Y-m-d` again, and then check if that matches your original input. – CBroe Aug 26 '20 at 12:10
  • Thank you for your answer i have understood your answer clearly and yes you provided me with accurate link about this issue. – ahmed nsreldeen Aug 26 '20 at 12:53

0 Answers0