CodeIgniter Forums
valid_date not working as expected - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: valid_date not working as expected (/showthread.php?tid=79054)



valid_date not working as expected - sfarzoso - 04-14-2021

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


RE: valid_date not working as expected - pars1997 - 04-14-2021

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