Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate Date time through laravel Validation

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

like image 618
user3653474 Avatar asked Apr 20 '26 01:04

user3653474


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'
like image 79
azibom Avatar answered Apr 26 '26 12:04

azibom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!