0

I need to encode an htmlhelper date to "{0:dd/mm/yyyy}. Current result in dd/mm/yyyy hr:mins:sec

<%= Html.Encode(Model.myTable.DOB)%>

I also need to enforce a datepicker to format "dd/mm/yyyy".

<%= Html.DatePicker("DOB", "/Content/Images/calendar.png", Model.ApplicantStatus.DOB)%>
dmarkez
  • 73
  • 1
  • 2
  • 11

2 Answers2

0

to mask date on Html.Encode, use:

<%= String.Format("{0:dd/MM/yyyy}", Model.myTable.DOB%>

to format dd/mm/yyyy, use:

<input type="image" src="/Content/Images/calendar.png" id="DOB" name="DOB" value='<%=String.Format("{0:dd/MM/yyyy}", Model.myTable.DOB)%>'/>
dmarkez
  • 73
  • 1
  • 2
  • 11
0

You can go to the datepicker class, and set up default value to the correct

dateFormat: 'dd/mm/yy'

and value you format as:

Model.myTable.DOB.ToString("dd/MM/yyyy")

and if you provide new value for the element use following

<%: Html.Helper("yourfield", new {ID="datepicker", @Value="your newValue"})  %>

good luck

cpoDesign
  • 8,953
  • 13
  • 62
  • 106