Start Datepicker with current day

Asked

Viewed 6,627 times

0

I have a record where I have two dates being: DataInicial and DataFinal, I’m using the DataPicker to insert both, as I can leave the DataInicial always with today’s date, I can’t allow retroactive dates. I saw some tips like that, but it didn’t work, look:

Jquery Date Picker Default Date

2 answers

3


Try this:

$('#datepicker').datepicker("setDate", new Date());

<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<div class="input-append date" id="datepicker" data-date="dateValue: Customer.DateOfBirth" data-date-format="dd-mm-yyyy">
<input class="span2" size="16" type="text" data-bind="value: Customer.DateOfBirth" readonly="readonly" />
<span class="add-on"><i class="icon-calendar"></i>
</span>
</div>

See working on jsfiddle

Refencia:

Set Today’s date as default date in jQuery UI datepicker

Bootstrap datepicker

  • Hello @Diegofelipe, I made the change but the field does not show me the date, where the ID "#mydata" in my case is called "#Initial date".

  • @adventistapr your date field is a correct text input type?

  • Yes, it looks like this: <input name="dDataInitial" type="text" class="form-control" id="dDataInitial">

  • I’ll add an example from the same Soen post, see if it helps you.

  • Hello @Diegofelipe, change something if you say I’m using Datapicker for Bootstrap?

  • @adventistapr but bootstrap datepicker needs jquery. See requirements here. Add <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> after the bootstrap js lib in your code and see if it works.

  • @adventistapr edited the answer, see if it now works.

Show 2 more comments

0

 
$("#seu_campo_id").datepicker({defaultDate: "getDate()",
                      dateFormat: 'dd/mm/yy',
                      dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado','Domingo'],
                      dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
                      dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
                      monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
                      monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
                      changeMonth: false,
                      numberOfMonths: 1,
                      minDate: 0}).datepicker("setDate", new Date());
 

  • A little explanation of the code would help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.