Carbon check date
Hello i need to check if a date is in format dd-mm-yyyy
i am using carbon and doing something like this:
I recibe the date from $request->date in this exemple i use the date 10-05-19901
$date = '10-05-19901';
if(Carbon::createFromFormat('d-m-Y', $date) !== false){
...
}
it shows error: Trailing data
The goal is to try check if is valid or not!
Thanks!
$request->validate([
'date' => 'date_format:d-m-Y',
]);
but i want do something like
if ( !empty($date) || check if date is valid format ){
....
}
Thats the reason for carbon i think!
Thanks.
$request->validate([
'date' => 'nullable|date_format:d-m-Y',
]);
Add nullable?
Sorry it was my fault not put all what i want lol sorry! The goal is doing this
$date = $request->date
if ( !empty($date) || ('check if $date is valid format') ){
$setDate = true;
}else{
$setDate = false;
}
i need to pass this parameters!
Thanks again!
Oh. Okay, glad to hear.lmao
But do you know any solution?To check if is valid format? thanks in advance
$setDate = false;
$request->validate([
'date' => 'nullable|date_format:d-m-Y',
]);
if ($request->filled('date')) {
$setDate = true;
}
Try this approach.
Please or to participate in this conversation.