I am using the Jquery datepicker from the website to allow users to select date and was wondering if it would be possible for the displayed date to be shown is the UK format of the date for example 22nd September 2012 is shown in the uk as 22/09/2012 while in American format its 09/22/2012
-
1http://stackoverflow.com/questions/1328025/jquery-ui-datepicker-change-date-format – Pete Mar 18 '13 at 16:10
4 Answers
try this:
$('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' });
$.datepicker.formatDate( format, date, settings )
Format a date into a string value with a specified format.
The format can be combinations of the following:
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)
! - Windows ticks (100ns since 01/01/0001)
'...' - literal text
'' - single quote
anything else - literal text

- 57,112
- 28
- 117
- 166

- 8,252
- 7
- 42
- 60
Use one of the following
$('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' });
$('#datepicker').datepicker({ dateFormat: 'dd/mm/yy' });
$('#datepicker').datepicker({ dateFormat: 'dd-M-yy' });
$('#datepicker').datepicker({ dateFormat: 'dd-MM-yy' });

- 8,252
- 7
- 42
- 60

- 1,715
- 2
- 10
- 7
As per ebram tharwat answer:
I have changed: $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' });
to $('#datepicker').datepicker({ format: 'dd-mm-yy' });
and this has worked for me

- 1
- 1

- 1,579
- 2
- 11
- 15
-
Can you explain what difference your code is? And when you say "worked for me" do you mean the previous answer did not? – user2903379 Aug 11 '18 at 23:18
As per @user2903379 question to @campervancoder answer:
$('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' });
Will change the order of day/month/year
$('#datepicker').datepicker({ format: 'dd-mm-yyyy' });
Will also change the / (slash) between values to a - (hyphen) so that the date is represented in the same way that it is stored in MySQL (albeit back-to-front). Note that I also had to use the 4 letter year representation otherwise the datepicker only returned a 2 digit year.

- 1,393
- 10
- 18