0

I am using jQuery datepicker for my project. I have this code:

$('#date-show').datepicker({ dateFormat: 'dd-mm-yy' });

My gripe is that although the datepicker shows, the date format is still 'mm-dd-yyyy') and I had also tried

$('#date-show').datepicker("option","dateFormat","dd-mm-yy");

It still displays as mm-dd-yyyy. Am I missing out something?

2
  • The format mantains 'mm-dd-yyyy' format each date you pick in the calendar, or you're sending a 'mm-dd-yyyy' format data to the component in the load time and it's not assimilating? Your second code is correct anyway. Commented Sep 1, 2016 at 2:35
  • @ExcubeDzynes, Did you check the answer? Commented Sep 2, 2016 at 3:33

1 Answer 1

1

Not sure if the problem you has was with day/month or with the number of digits for year, but this code works:

$('#date-show').datepicker({ dateFormat: 'dd-mm-yy' });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>
<input id="date-show" name="date-show" />

If you need the year to be 2 digits (instead of 4) you should use only 1 y (and not 2).

$('#date-show').datepicker({ dateFormat: 'dd-mm-y' });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>
<input id="date-show" name="date-show" />

Sign up to request clarification or add additional context in comments.

5 Comments

Not sure who the downvoter is, but it will be great to get an explanation for the downvote
I was sure his problem is with mm-dd vs dd-mm. The yy is for 4 chars year. If he wants 2 he can use only 1 y.
@epascarello, answer updated, I think you can change the downvote
@ExcubeDzynes, if the answer is correct you should I would appreciate it if you accept/vote it up. If it doesn't solve your problem please try to add more information/code sample and I'll try to help.
it doesn't work for me but I surmise it works in jsFiddle, so I'll accept it

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.