Q:

input datetime set string.format to model item

I've an input of type datetime
   <input type="datetime" id="DATA_END_@id" value="@String.Format("dd/MM/yyyy",item.DATA_END_PREZZATURA.ToString())" />

I need to set the model item value in the datetime format dd/MM//yyyy
What is the right sintax?
Thank you!
In the end this was the solution
@{
                string value_d_s = "";
                DateTime? dateOrNull = item.DATA_END_PREZZATURA;
                if (dateOrNull != null)
                {
                    DateTime date_d_s = dateOrNull.Value;
                    value_d_s = date_d_s.ToString("dd/MM/yyyy");
                }

             }

            <input type="datetime" id="DATA_END_@id" value="@value_d_s" />     

A:

Use an overload of the DateTime.ToString() method to format your date.
<input type="datetime" id="DATA_END_@id" value="@item.DATA_END_PREZZATURA.ToString("dd/MM/yyyy")" />

If item.DATA_END_PREZZATURA is a string instead of a DateTime, you will need to use DateTime.TryParse():
@{
    DateTime test;
    DateTime.TryParse(item.DATA_END_PREZZATURA, out test);
}
<input type="datetime" id="DATA_END_@id" value="@test.ToString("dd/MM/yyyy")" />

Note you will need to handle the case when TryParse fails.

