vamsi kr
vamsi kr

Reputation: 421

Datetimepicker unable to select the todaydate

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.

Upvotes: 5

Views: 8439

Answers (6)

MohitGhodasara
MohitGhodasara

Reputation: 2732

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()

Upvotes: 0

Dharmesh Rakholia
Dharmesh Rakholia

Reputation: 1238

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

Upvotes: 3

Aman Singh
Aman Singh

Reputation: 61

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.

Upvotes: 6

Eonasdan
Eonasdan

Reputation: 7765

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.

Upvotes: 0

Kalu Singh Rao
Kalu Singh Rao

Reputation: 1697

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
                });

Upvotes: 0

sanjeev
sanjeev

Reputation: 4621

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"});

Upvotes: 1

Related Questions