Validate Date time through laravel Validation

Viewed 2952

I'm trying to validate date time through Laravel Validation like this:

$this->validate($request,[
        'DateTime'=> 'required|after_or_equal:' . date('Y-m-d H:i:s'),
]);

I want to restrict the user if they enter date time greater than current date time but in my case date is being validated but i have to validate time also. Format of date time is 2020-12-23 17:40:00

1 Answers

Try this:

$this->validate($request,[
        'DateTime'=> 'required|date_format:Y-m-d H:i:s|after_or_equal:' . date(DATE_ATOM),
]);

And if you want to change the time you can do sth like this:

'request_date'=>'after:'.date(DATE_ATOM, time() + (5 * 60 * 60)),

Or

'request_date' => 'required|date_format:Y-m-d H:i:s|after:5 hours'
Related