Laravel 5.8 - Validate future date - laravel

How do I validate that a given date is in the future and not a past date? Alternatively, does Html 5 allows one to disable past date from a date field?
I have a form in my app that allows user to select start date for an event from an HTML date input field. I want users to only choose a date in the future and not a past date.

I think you can use it like this:
$rules = [
'start_date' => 'date_format:d/m/Y|after:3/13/2019',
];
See also the laravel documentation:
https://laravel.com/docs/5.8/validation#rule-after
or
https://laravel.com/docs/5.8/validation#rule-after-or-equal

after:today works as #Tim Lewis commented above.
As for HTML validation, date fields still aren't fully supported. Safari being the main culprit.
You can use min="2020-01-01" format against the input, but you'll need to either add that date server-side or using JavaScript so it's tomorrow's date.

I have tried code and found that if you want to validate only year than you can write something like
$rules = ['dob'=>'required|date_format:Y|before:today']
where,
date_format
is fixed keyword and with help of 'Y' you can validate only year
and before:today validate if year is older than today or not.
you can use d-m-Y format instead only Y.
happy coding...

Related

How to select format date using carbon?

How to select format date using carbon ?
I'm used format ->select(DB::raw("(DATE_FORMAT(score_dt, '%M'))")) before.
I want to change the format by using carbon, how do I use it in a select query? to display month name
Have a read of the Carbon docs. Laravel uses Carbon 2 now.
You should be able to get the month name with the monthName property: $yourDateObject->monthName.
Carbon, however, is a PHP library and is not part of the database you're using. This means you can't use it in your select query, to use Carbon, you'll need to format your data in your model/controller/frontend. This is a fairly standard way of turning ISO8601 dates into human readable form.

Date Picker Validation Start Date

I am new to the environment and need help writing a validation statement in APEX.
I have a Start Date and End Date field on a page with a Date Picker Type.
The End Date validation has already been set ( end date must be equal to or greater than start date )
Now I need to implement this validation for start date:
User should be able to choose either the current date (today) or a future date.
Is there a way to disable previous days on Apex? Or would I need to write a validation statement? If so, what validation statement could I use?
Check out the settings for the date picker, specifically the minimum date.
Use the help to work out exactly what you need. APEX will then handle the validations for you.

only show events who are greater than or equal laravel

Im working in a project where I display different events in my view. The goal for now is to only show events that are upcoming, so it doesn't show events that are older than today.
The users of my page can create an event and set a sertain date for it.
The data is stored into my db like this:
$table->string('datum');
In the view it return it like this:
06.03.2019
My controller to return the data looks like this:
$date = date('d.m.Y');
$evententries = Event::where('datum', '>=', $date)->orderBy('datum', 'asc')->take(3)->get();
but it's somehow not working..
Anyone got any Ideas of how to fix this and what my issue is here?
btw, I'm using laravel 5.7.
Thank you :)
Hmm you are doing it on wrong way from begin...
First: why you are using string to store date value? there is much better options to store date within database...
Second: you are using date format which cannot be compared on that way (using < > =)
when you are comparing strings ie 08.03.2019 will be always smaller than 10.01.2016 because 1 > 0... so if you are comparing dates use:
db format for storing dates
for comparing use format yyyy-mm-dd because on that way even simple string comparison will give you correct result...

Joomla article field date minimum limit

I am Building a Family site with Joomla 3.7.3 and are trying to add custom fields to the articles. I am e.g. adding the birthday of a Family member in a field. But, it seems like I cannot create a date before 1900-01-01. Do you know of a workaround for this and maybe why one would add this limit to a date field?
Note: I see that there is an option called: "minyear" in the documentation. It might solve the problem, but how do you use it?
Even though the datepicker popup only goes back to 1900, you can manually type in whatever date you want.
You can change the date format disabled by going to Language Overrides and changing the constant of DATE_FORMAT_LC4 to F d, Y or whatever format you want.
If you want to tinker with the datepicker functionality, I believe those files are in /media/system/js/

disable drupal date validation

I have a date field (widget = select list) in a drupal 7 content type, And I want to be able to enter a date like 2012/2/31 without any validation error?
what can I do?
The problem is 2012/2/31 is not a date, it's just a text string that resembles the formatting of a real date.
If you don't want to use proper, valid dates, then you simply shouldn't be using a date field. I'd advise adding a text field instead and then using the Field validation module to define a pattern to test the input against. That way you can accept any kind of string that resembles a date, not just real dates.
You can use date module, it provides you a date picker widget and output will be same as 2012/2/31, either you have to use textfield widget.
Date Module

Resources