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

danny620's avatar

How to repopulate date of birth dropdowns

Deleted

0 likes
3 replies
moharrum's avatar

I know this is not the answer for your question, but there are easier ways to do this. A tool like datepicker will construct the dob html for you with a nice design, and it has an option for setting the default date/time:

$(".date-pick").datepicker('setDate', new Date());

Consider this tool, it will save you some code.

EDIT:

To answer your question, you need to do some if checks:

$dt = Carbon::parse('2016-4-24 20:23:12.123789');

and in view

@if($dt->year == $i) // ---> I think you are doing some kind of a loop to print years
    <option value="$i" selected="selected">$i</option>
@endif
Snapey's avatar

when you are listing the select options you have to check if it matches the current value. As described by @moharrum

jlrdw's avatar

Maybe a light bulb will come on and you will realize you can still use date picker with three boxes there is a way to have drop-downs and datepicker simultaneously Google it.

Please or to participate in this conversation.