Reputation: 411
How do i default to date only in the jquery date time picker. The first time the page loads the text box defaults to both date and time but after i choose a date it only shows the date portion. The date is bound to a model.
View code
@Html.EditorFor(m=>m.EndDate)
@*java script*@
$(function () {
$("#EndDate").datepicker(
{
dateFormat: 'yy/mm/dd',
changeMonth: true,
changeYear: true,
minDate: new Date()
});
});
So what i want is the datetime textbox to always show date only without time.
Upvotes: 0
Views: 1427
Reputation: 3082
You better create a custom function to convert DateTime object to date and use this in he view.
Server side:
public static string ShowDate(this DateTime dateTime)
{
string dateFormat = String.Empty;
dateFormat ="yy/mm/dd";// or the format you need
return dateTime.ToString(dateFormat);
}
In the view:
@Html.TextBoxFor(model => model.EndDate, new { @Value =Model.EndDate.DisplayDate() })
Upvotes: 1