1

In my code I want to set the format of dates to d MM yy. I've tried the following but with no success:

$().ready(function () {

        $.datepicker.setDefaults({ dateFormat: 'd MM yy' });


        $("#Client_DateOfBirth").datepicker(
        {
            maxDate: "+0D",
            dateFormat: 'd MM yy'
        });
});

The date is set as follows:

<div class="registration-item">
    <%: Html.LabelFor(model =>model.Client.DateOfBirth) %>
    <%: Html.TextBoxFor(model => model.Client.DateOfBirth)%>
    <%: Html.ValidationMessageFor(model =>model.Client.DateOfBirth) %>
</div>

The value is displayed as: 15-8-1988 0:00:00. I don't want this,I want 15 aug 1988.

When I pick a value from the datepicker,I get the right value. But when a value is already set,the format is not applied. How can I do this?

1 Answer 1

1

If the date is formatted correctly when you select a date from the datepicker, it means that the date needs formatting when initially put in the input by your ASP code. Try formatting the date like this:

<%: Html.TextBoxFor(model => model.Client, new { @Value = model.Client.DateOfBirth.ToString("d MMM yyyy") }) %>

More information of date formatting in C#

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.