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

cklester's avatar

How to Pass Date Field to Date Formfield

I'm trying to set the value attribute of a date input to the current value in the database, but nothing shows up there. I can do the time field just fine. But the date field on the form shows the placeholder, 'mm/dd/yyyy,' instead of the date value I send it. I've even tried a manual entry of a date, but the form field is still blank! I have a date in the record, and I'm trying to allow the user to change it, but I can't populate the form with the current date.

What's the secret?! :D

0 likes
5 replies
DarkRoast's avatar

The format for the html date input type needs to be yyyy-mm-dd - that can't be changed as far as I can tell.

cklester's avatar

I'm not casting it with a mutator. I'll consider that in the morning. Thank you, guys!

cklester's avatar

My database has a DATE field with a value of 2017-02-25. When I bring that to the HTML page, it includes a timestamp. How do I make sure the field is used and displayed only as a date field?

I have this in my model:

    protected $dates = ['created_at', 'updated_at', 'party_date', 'deleted_at'];
    protected $guarded = [];
    protected $casts = [
        'party_date' => 'date',
        ];

Please or to participate in this conversation.