5

Datetimepicker unable select today's date.Suppose When we open the datetimepicker and change the date and select the today date it is not selected.And we used the Bootstarp datetimepicker.

$('#datetimepicker1').datetimepicker().data("DateTimePicker").options({format: "DD/MM/YYYY",minDate:new Date()});

Thank you.

vamsi kr
  • 431
  • 1
  • 4
  • 13

6 Answers6

5

You have to integrade use Below code to select the todaydate

minDate: new Date().setHours(0,0,0,0)

$("#startdatetimepicker").datetimepicker({ minDate : new Date().setHours(0,0,0,0),format: 'DD-MM-YYYY'});

  • It select the today's date also after picked another date and go for select today's date.
  • It's also disable the previous date.
Aman Singh
  • 51
  • 1
  • 4
3

You're setting the minDate to today, which means won't be able to select it.

Instead, set minDate to

 minDate: moment().millisecond(0).second(0).minute(0).hour(0)

which will be today. for more info : https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1302#issuecomment-141923309

Dharmesh Rakholia
  • 1,210
  • 9
  • 22
1

You are setting the minData to new Data()

new Data() by default gives the current data.

So In your case you are not able to select not only today's date but all the past date.

So simple remove the minData parameter(as below), or use it a different way.

$('#datetimepicker1').datetimepicker().data("DateTimePicker").options({format: "DD/MM/YYYY"});

sanjeev
  • 4,405
  • 2
  • 19
  • 27
  • In this case we able to select the previous dates too.So that's y we used the minDate.Is there any solution for this(Not select previous dates) @sanjeev – vamsi kr Sep 07 '15 at 05:09
  • @vamsikr As the Datetimepicker uses Moment, the best way to get yesterday is `moment().subtract(1, 'day')` – P_S Sep 07 '15 at 12:57
0

You should use following code.

 <script src="/assets/js/plugins/datetime/bootstrap-datetimepicker.min.js"></script> 
    $('#datetimepicker1').datetimepicker({
                    weekStart: 1,
                    todayBtn: 1,
                    autoclose: 1,
                    todayHighlight: 1,
                    startView: 2,
                    minView: 2,
                    forceParse: 0
                });
Kalu Singh Rao
  • 1,671
  • 1
  • 16
  • 21
0

You're setting the minDate to today, which means won't be able to select it.

Instead, set minDate to minDate: moment().subtract(1,'d') which will be yesterday.

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
0

You just need to pass the date as a string and the rest will be handled by the library itself

moment().format('YYYY/MM/DD')

or

new Date().toDateString()
MohitGhodasara
  • 2,342
  • 1
  • 22
  • 29