Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

Validate dates with "now" or "yesterday" words in Laravel


You can validate dates by rules before/after and passing various strings as a parameter, like: "tomorrow", "now", "yesterday". Example: 'start_date' => 'after:now'. It's using strtotime() under the hood.


$rules = [
 'start_date' => 'after:tomorrow',
 'end_date' => 'after:start_date'
];

 

Other date validation rules:

 

date

The field under validation must be a valid, non-relative date according to the strtotime PHP function.

 

date_equals:date

The field under validation must be equal to the given date. The dates will be passed into the PHP strtotime function.

 

date_format:format

The field under validation must match the given format. You should use either date or date_format when validating a field, not both. This validation rule supports all formats supported by PHP's DateTime class.

 

before:date

The field under validation must be a value preceding the given date. The dates will be passed into the PHP strtotime function. In addition, like the after rule, the name of another field under validation may be supplied as the value of date.

 

before_or_equal:date

The field under validation must be a value preceding or equal to the given date. The dates will be passed into the PHP strtotime function. In addition, like the after rule, the name of another field under validation may be supplied as the value of date.

 

after:date

The field under validation must be a value after a given date. The dates will be passed into the strtotime PHP function:

'start_date' => 'required|date|after:tomorrow'

Instead of passing a date string to be evaluated by strtotime, you may specify another field to compare against the date:

'finish_date' => 'required|date|after:start_date'

 

after_or_equal:date

The field under validation must be a value after or equal to the given date. For more information, see the after rule.

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon