April 7, 2012

Change date Format in jQuery DatePicker to English dd/mm/yy?

Question by MickySmig

I’m trying to format the date of a jQuery DatePicker to the English format ‘dd-mm-yy’, but I’m unable to get it to work. I’ve looked at all of the answers on this site and they all are using the same code as I am. Any idea why mine is not working? I have tried the two following ways:

$(function () {
    $(".datefield").datepicker({dateFormat:'dd/mm/yy'});
});

$(function () {
    $(".datefield").datepicker({ dateFormat: 'dd-mm-yy' });
});

Neither of these have worked. I was wondering if I had to include some other jQuery file to get the date to format to English.

Any help, as always, is greatly appreciated.

Answer by Starx

If you are trying to change it, use the setter method

$( ".datefield" ).datepicker( "option", "dateFormat", 'yy-mm-dd' );

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!