I am using jquery UI datepicker on MVC2 to set my startdate picker.
When I go to the 'create' view, I want the datepicker to hold its minimal value- which is today.
But for some reason I see the date format string like this: mm/dd/yyyy HH:MM:SS AM or PM. only before the user pick a date- after the user picks a date I get the format that I want: mm/dd/yyyy in both of my datepickers- dateStart and dateEnd
and when I go to edit, I get the value from the database (date datatype) and have the same problem. this is my code:
$(function () {
var buttonImage = $(".selector").datepicker("option", "buttonImage"); // date image
// Datepicker
$('#DateStart').datepicker({
inline: true,
showOn: 'both',
buttonImage: '/Content/calandar2.gif',
minDate: '+0',
dateFormat: 'mm/dd/yy',
onSelect: function (dateStr) {
var min = $(this).datepicker('getDate') || new Date(); // Selected date or today if none
$('#DateEnd').datepicker('option', { minDate: min });
}
});
$('#DateEnd').datepicker({
开发者_运维问答 inline: true,
showOn: 'both',
buttonImage: '/Content/calandar2.gif',
dateFormat: 'mm/dd/yy',
minDate: '+0'
});
}
THANK YOU!!!
It sounds like your issue is with the HtmlHelper and the DateTime value.
<%=Html.TextBoxFor(model=>model.SomeDate) %>
or
<%=Html.EditorFor(model=>model.SomeDate) %>
Which by default will call DateTime.ToString()
If that is the case you can either convert it to be simply
<%
var theValue = //something to get your date time and call .ToShortDateString()
%>
<%=Html.TextBox("DateStart", value) %>
If you are using templates you can also do this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%
string value;
if (Model.HasValue && Model.Value != DateTime.MinValue)
value = Model.Value.ToShortDateString();
else
value = string.Empty;
%>
<%=Html.TextBox("", value) %>
精彩评论