Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Cosmin89's avatar

Store date from datepicker into db

I'm trying to store a date from jquery datepicker into the db using laravel ofc. Also I need to check if the selected date is the current date.

0 likes
8 replies
mindz's avatar

You must be more precise

If you want to check if datepickers date is current (i assume today)

Carbon::parse($request->get('datepicker')->eq(Carbon::today()))
Cosmin89's avatar

It seems the date format from the datepicker is not the same as the carbon instance.

I need the carbon instace to be in this format "yy-mm-dd", to work.

I've done it. Is there a way to check the date with validation rules ?

mindz's avatar

@Cosmin89

$formatOfDateYouWant = Carbon::parse($request->get('datepicker')
->eq(Carbon::today()))->format('yy-mm-dd')
Cosmin89's avatar

If I use in the custom validation rules "date_format:yy-mm-dd" the same format as the datepicker format, it says that "does not match the format yy-mm-dd. "

What format should I use then ?

mindz's avatar

Dont know what plugin you use but there is a possibility to customize format

var date = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' }).val();
Cosmin89's avatar

I've set it to "yy-mm-dd", in the datepicker and validation rule. No matter what format I choose it seems wrong.

deansatch's avatar

dd($request->get('datepicker')); and see what you get

Please or to participate in this conversation.