Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cluel3ss's avatar

Validation: Form input should be greater than literal date value

I have created a Form Request which validates an input labelled start_date. This date needs to be greater than a literal value 2016-06-31.

This is the rule I have build in my form request file:

    public function rules()
    {
        return [
            'start_date' => 'required|date|date_format:Y-m-d|after:2017-06-31',
        ];
    }

This is what is sent in my form request

{
"token": "tZa4e39ejrGHtrlpOYrUPfZ8PgSeD8FelY4voKni",
"start_date": "2017-07-01"
}

However I get an error saying "The start date must be a date after 2017-06-31." regardless of what date I put in there.

0 likes
7 replies
Cronix's avatar

get rid of the date rule. The docs say to use date or date_format, but not both

cluel3ss's avatar

Thanks, I have removed the date rule but this hasn't solved my problem

Cronix's avatar

Maybe you need to put double quotes around the date. Not sure, but I've seen other examples that use it.

after:"2017-06-31"

What's happening? Do you actually get any errors or anything?

cluel3ss's avatar

@Cronix Updated the original post.

I've added double quotes around the dates but it still returns "The start date must be a date after 2017-06-31." error despite the date being 2017-01-01.

Cronix's avatar

Well, 2017-01-01 isn't after 2017-06-31, it's before. Try 2017-07-01 or something.

Cronix's avatar
Cronix
Best Answer
Level 67

Also, June doesn't have 31 days, it has 30. (2017-06-30)

cluel3ss's avatar

Ah I think this is why it's not been working all this time!

Changes to 2017-06-30 and its working now :-)

Please or to participate in this conversation.