Pankaj
Pankaj

Reputation: 10095

Issue in Date Format in Laravel

I am using below code.

public function rules()
{
    return [
        'SuspensionHistoryDate' => 'required|date_format:"mm/dd/YYYY"',
    ];
}

below is the value that I tried to post "03/23/2016".

I am getting below mentioned message.

The d l issue date does not match the format MM/DD/YYYY.

Can you please guide if I am missing anything?

Upvotes: 1

Views: 695

Answers (1)

James
James

Reputation: 16339

As per the comments you need to be setting the date format as a valid PHP format - which mm/dd/YYYY isn't.

You can see more on the available formats that PHP will accept here, but based off you wanting a month/day/year format then this would work:

public function rules()
{
    return [
        'SuspensionHistoryDate' => 'required|date_format:"m/d/Y"',
    ];
}

Note that using d means that the day needs to be represented as two digits and so may need to have a leading zero. You can use j instead to still have a numerical representation without leading zeros.

Upvotes: 1

Related Questions