27
votes

I'm using bootstrap datepicker on a textbox. The default format of the date when you select a date is mm/dd/yyyy. Now I want to change it to dd/mm/yyyy. How can I accomplish this. Right now I'm just initializing it just like this.

$('.datepicker').datepicker()

What should I add to change its format?

10

10 Answers

64
votes

See http://www.eyecon.ro/bootstrap-datepicker/

 $('.datepicker').datepicker({
    format: 'dd/mm/yyyy'
 });
12
votes

As of 2016 I used datetimepicker like this:

$(function () {
    $('#date_box').datetimepicker({
        format: 'YYYY-MM-DD hh:mm'
    });
});
11
votes

I am using Bootstrap v3.3.4 and using the code:

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

Output is: 16-07-2015

Note: only need "yy" for full year.

2
votes

If by ID:

$('#datepicker').datepicker({
    format: 'dd/mm/yyyy'

});

If by Class:

$('.datepicker').datepicker({
    format: 'dd/mm/yyyy'

});
2
votes

this works for me

Open the file bootstrap-datepicker.js

Go to line 1399 and find format: 'mm/dd/yyyy'.

Now you can change the date format here.

1
votes

File name : bootstrap-datepicker.js Line No : 41:

this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||dates[this.language].format||'mm/dd/yyyy');
0
votes

Easy way:

Open the file bootstrap-datepicker.js

Go to line 1399 and find format: 'mm/dd/yyyy'.

Now you can change the date format here.

0
votes

for me with bootstrap 4 datetime picker (http://www.eyecon.ro/bootstrap-datepicker/) format worked only with upper case:

$('.datepicker').datetimepicker({
            format: 'DD/MM/YYYY'
        });
0
votes
  $(function () {
    $('.datetimepicker').datetimepicker(
      {
        format: 'Y-m-d h:m:s'
     }
    );
 });`
-2
votes

If you are using new jqueryui above code will not help you use this

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