Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap datepicker setDate format dd/mm/yyyy

I have to set the date in my datepicker in dd/mm/yyyy format. Whet I'm trying to do, with Javascript is this:

  var year = 2014;   var month = 5;   var day = 10;    var realDate = new Date(year, month - 1, day); // months are 0-based!    $('#MainContent_txtDataConsegna').datepicker({ dateFormat: 'dd/mm/yyyy' }); // format to show   $('#MainContent_txtDataConsegna').datepicker('setDate', realDate); 

the problem is that the value inside my datepicker is always in format mm/dd/yyyy. Where is the problem??

Here the definition datepicker and datepicker options:

   <div class="input-group date">        <asp:TextBox runat="server" ID="txtDataOrdine" class="form-control" onBlur="CalcolaTotaliTestata('txtDataOrdine')"></asp:TextBox>        <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i>/span>     </div>  <script type="text/javascript">    $('.input-group.date').datepicker({        todayBtn: "linked",        language: "it",        autoclose: true,        todayHighlight: true,        dateFormat: 'dd/mm/yyyy'     }); </script> 
like image 835
Martina Avatar asked May 18 '14 19:05

Martina


People also ask

How do I change datepicker format from DD MM to YYYY?

var year = 2014; var month = 5; var day = 10; var realDate = new Date(year, month - 1, day); // months are 0-based! $('#MainContent_txtDataConsegna'). datepicker({ dateFormat: 'dd/mm/yyyy' }); // format to show $('#MainContent_txtDataConsegna'). datepicker('setDate', realDate);

How do I change date format in datepicker?

Here's one specific for your code: var date = $('#datepicker'). datepicker({ dateFormat: 'dd-mm-yy' }). val();


2 Answers

Change

dateFormat: 'dd/mm/yyyy' 

to

format: 'dd/mm/yyyy' 

Looks like you just misread some documentation!

like image 103
ntzm Avatar answered Sep 21 '22 22:09

ntzm


Changing to format: 'dd/mm/yyyy' didn't work for me, and changing that to dateFormat: 'dd/mm/yyyy' added year multiple times, The finest one for me was,

dateFormat: 'dd/mm/yy' 
like image 27
Shree Krishna Avatar answered Sep 24 '22 22:09

Shree Krishna