21

I would have thought this was:

.datepicker({ dateFormat: 'dd-mmm-yyyy' });

for month, I get some number that I don't understnad where they are coming from?

Kiran Joshi
  • 1,758
  • 2
  • 11
  • 34
leora
  • 188,729
  • 360
  • 878
  • 1,366

5 Answers5

47

According to the documentation, a single M is "Month name short" and "yy" is "Four Digit Year."

dd-M-yy
Sampson
  • 265,109
  • 74
  • 539
  • 565
23

This is a case where looking into the documentation is most helpful:

*  d - day of month (no leading zero)
* dd - day of month (two digit)
* o - day of the year (no leading zeros)
* oo - day of the year (three digit)
* D - day name short
* DD - day name long
* m - month of year (no leading zero)
* mm - month of year (two digit)
* M - month name short
* MM - month name long
* y - year (two digit)
* yy - year (four digit)
* @ - Unix timestamp (ms since 01/01/1970)
* '...' - literal text
* '' - single quote
* anything else - literal text 
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
12

You want:

$('.selector').datepicker({ dateFormat: 'dd-M-yy' });

See the docs.

The date format strings are somewhat non-standard:

d - day of month (no leading zero)
dd - day of month (two digit)
o - day of the year (no leading zeros)
oo - day of the year (three digit)
D - day name short
DD - day name long
m - month of year (no leading zero)
mm - month of year (two digit)
M - month name short
MM - month name long
y - year (two digit)
yy - year (four digit)
@ - Unix timestamp (ms since 01/01/1970)
'...' - literal text
'' - single quote
anything else - literal text

Dominic Rodger
  • 97,747
  • 36
  • 197
  • 212
3

The correct way is dd-M-yy

Alternatively you can use the monthNamesShort option for custom names ..

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
0

If you are using AUI Datepicker / Datepicketselect components then dateFormat usage is a bit different.

for eg: if you want to display 01-Jan-2014, you will have to use dateFormat:'%d-%b-%Y'

following is the documentation that explains different formats: http://alloyui.com/versions/1.5.x/api/classes/DataType.Date.html

My working code: (on Liferay with AUI)

<div id="myDatepicker"></div>
  <input type="text" name="myDateValue" id="myDateValue" size="9" /> 

<aui:script>
  AUI().use('aui-datepicker', function(A) {
     new A.DatePickerSelect(
       {
         appendOrder: ['d', 'm', 'y'],
        calendar: {
        dateFormat: '%d-%b-%Y'
    },
    boundingBox: '#myDatepicker',
    trigger: '#myDateValue'
  }
).render();
}
);
</aui:script>
Jose Magana
  • 931
  • 3
  • 10
  • 24