Search code examples
htmlcoldfusioncfmlhtml-inputcoldfusion-2018

Defaulting a date field in ColdFusion


I want to default a date input control to today

<cfoutput>
    <input type="date" class="form-control" name="dtStart" value="#LSDateFormat(now(), 'mm/dd/yyyy')#" required />
    <br />
    My Date: #LSDateFormat(now(), 'mm/dd/yyyy')#
</cfoutput>

All I get out of this is

enter image description here

Is there a way to get it to default to today?


Solution

  • You can use code like below ( Set mask as 'yyyy-mm-dd' ) , It will show default value as the current date for your input date field.

    <cfoutput>
        <input type="date" class="form-control" name="dtStart" value="#LSDateFormat(now(),'yyyy-mm-dd')#" required />
        <br />
        My Date: #LSDateFormat(now(), 'mm/dd/yyyy')#
    </cfoutput>
    

    Code result as screenshot

    enter image description here