Welcome Guest, Not a member yet? Register   Sign In
valid_date not working as expected
#1

I'm trying to validate this date: 14/04/2021 16:00, so inside the validation rules of the controller I did:


PHP Code:
        $validationRules = [
            'title'             => 'required|min_length[1]|max_length[60]',
            'author_id'         => 'required|integer',
            'status'            => 'required|in_list[draft,published]',
            'published_date'    => 'required|valid_date[d/m/Y H:m"]'
        ]; 

the problem's that when the code reach this line:


PHP Code:
if (!$this->validate($validationRules)) {
      var_dump($this->request->getPost('published_date'));
      var_dump(date("d/m/Y H:m"));
      var_dump($this->validator->getErrors());
      die();
      return redirect()->back()->withInput()->with('error'$this->validator->getErrors());
 

The field published_date must contains a valid date
Reply
#2

(This post was last modified: 04-14-2021, 11:43 AM by pars1997.)

you have to use i for minute (d/m/Y H:i).
more info: https://www.php.net/manual/en/datetime.format.php
Reply




Theme © iAndrew 2016 - Forum software by © MyBB