Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
555
IGDatePicker format issue
posted

 I want to show date in dd/mm/yyyy format but it always shows mm/dd/yyyy format. Also I want to set a default date to my control on page load

My view has:

<div class="col-md-4 col-sm-4 ">

@(Html.Infragistics().DatePicker()

.ID("TDate")

.ButtonType(TextEditorButtonType.DropDown)

.Render())

<input type="hidden" value="@ViewBag.TDate" id="hdnFlag" name="hdnFlag" />

</div>

My controller has :

public ActionResult Index()

{

ViewBag.TDate = "16-MAR-2017";

return View();

}

My javascript to set the default value is:

$(document).ready(function () {

var h1 = document.getElementById('hdnFlag');

if (h1 != null) {

h1 = h1.value.replace("-", " ");

h1 = h1.split("-").join(" ");

var twd = new Date(h1);

twd.toLocaleDateString("en-GB");

var d = twd.getDate();

var m = twd.getMonth();

var y = twd.getFullYear();

$("#TDate").igDatePicker({

value: new Date(y, m, d),

dateDisplayFormat: "dd/MM/yyyy",

minValue: new Date(y - 1, m, d)

})

}

});

I am not able to set the date correctly also if I change the date it shows in mm/dd/yyyy format.

Can anyone please help?

Regards

Singh

Parents
  • 2895
    posted

    Hello Singh,

    Thank you for using our community.

    I have created a basic MVC sample for you in order to show you how to display the value in the desired format. I’m not sure why you are initializing two times the editor. Here is a sample code that should help you:

    @(Html.Infragistics().DatePicker()

     .ID("TDate")

     .Value("16-MAR-2017")

     .DateDisplayFormat("dd/MM/yyyy")

     .DateInputFormat("dd/MM/yyyy")

    .Render())

    Please let me know if this is working for you.

    Best Regards,
    Marina Stoyanova,
    Software Developer,
    Infragistics, Inc.

Reply Children