1

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • 1
    Possible duplicate of [Is there any way to change input type="date" format?](https://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format) – rrk Aug 02 '19 at 06:45
  • `type="date"` fields are open for browser to implement based on browser/system locale/settings. Also if the `value` attribute should be in `yyyy-mm-dd` format. Then the default value will appear in the input field(formatted based on the browser setting). – rrk Aug 02 '19 at 06:51
  • This is not a dup because I am asking about how to set the value as opposed to how it is displayed. – James A Mohler Aug 02 '19 at 18:35
  • 2
    Possible duplicate of [How to set input type date's default value to today?](https://stackoverflow.com/questions/6982692/how-to-set-input-type-dates-default-value-to-today) – Alex Aug 02 '19 at 20:12
  • @Alex That is indeed a dup – James A Mohler Aug 02 '19 at 20:26

1 Answers1

2

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

Ravi B
  • 1,574
  • 2
  • 14
  • 31
Saravana Kumar
  • 168
  • 1
  • 9