0

I'm trying to use DateTimePicker in my application. I create Date.cshtml under the View/Shared/EditorTemplates folder and it consist something like this:

@model System.DateTime

@Html.TextBox("", Model.ToString("dd-MM-yyyy"),
new {@class = "tanggal", @maxlength = "10"})

then I create EditorHookup.js file under the script folder with the content like this:

$(document).ready(function () {
    $('.tanggal').datepicker({
        dateFormat: 'dd-MM-yyyy'
    });
});

I expect to get the result to be like this: 01-01-2012 but the result is: 01-January-20122012

What should I do to fix that?

3 Answers 3

2

Use mm for month instead of MM. See here: http://docs.jquery.com/UI/Datepicker/formatDate

E.g.:

dateFormat: 'dd-mm-yy'     //notice the year format also has been changed, per Izkata's comment
Sign up to request clarification or add additional context in comments.

6 Comments

Also, use 'yy' instead of 'yyyy'
If I change MM to mm in Date.cshtml, the month will be 00
@Tanu, sorry, the change needs to be made in the jQuery call: dateFormat: 'dd-mm-yy'.
Hi, Thanks for the help. I have made a changes in my .js file to 'dd-mm-yy', the month result is changed, but the year still double (01-01-20122012)
@Tanu, be sure the year is yy, not yyyy. See the documenation referenced.
|
1

Double-check the documentation for your datepicker, specifically regarding the code for month. I'd guess that you want something like mm instead of MM.

Comments

1

can you try

dateFormat: 'dd-mm-yy'

http://jqueryui.com/demos/datepicker/#option-dateFormat

2 Comments

the month result format is change to the expected, but the year still double (01-01-20122012)
Thank you very much. The datetimepicker is run as expected now

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.