Hey, you can actually chose the format you want to validate. Here are the docs: https://laravel.com/docs/6.x/validation#rule-date-format For example:
$rule['birthday'] = 'required|date_format:d/m/Y';
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, need a little help here.
I'm using a Javascript datetimepicker on my form, but when I'm trying to submit, it return this error
DateTime::__construct(): Failed to parse time string (20/11/2019) at position 0 (2): Unexpected character
I get that result when I'm using Carbon::parse() method to convert this $request->birthday that come in "DD/MM/YYYY" format.
When I'm using the Carbon::createFromFormat('d/m/Y', $request->birthday) I get the proper datetime result, but when hit the laravel date validation, it said the value is not a valid date. Where did I go wrong?
Pardon my bad english, it's not my native
I think that $request->validate is not returning the changed birthday date.
In your case I would validate the data in the form format first and then parse it to carbon format in order to save it.
public function store(User $user, Request $request) {
$validatedData = $request->validate([
'birthday' => 'sometimes|nullable|date_format:d/m/Y'
]);
$validatedData['birthday'] = Carbon::createFromFormat('d/m/Y', $request->birthday);
$user->profile()->store($validatedData);
return back();
}
I think something like this should work.
Please or to participate in this conversation.