Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using jquery datetime picker.

I want to disable date selection of dates previous to specific date.

for e.g.

if my date is 13/03/2016,
calendar starts from this date and enddate will be current date i.e. 13/05/2016.

user should not be able to select date before 13/03/2016 and after 13/05/2016.

What I have tried:

var t = $("#preDate").val();
 var jsDate = new Date(t);

var time = new Date().getTime();
var currentdate = new Date(time);

var datetime1= "-"+jsDate.getDate()+"/"+(jsDate.getMonth()+1) +"/"+jsDate.getFullYear();
var datetime2 = currentdate.getDate()+"/"+(currentdate.getMonth()+1) +"/"+currentdate.getFullYear();

 $("#myDtPicker").datetimepicker({
                minTime:0,
                minDate:datetime1,
                maxDate:datetime2,
                startDate:datetime1,
                endDate:datetime2,                
                formatTime: 'H:i',
                formatDate: 'd/m/Y',
            });


but it's not working..

What's wrong with the code?
Posted
Updated 12-May-16 20:11pm

1 solution

Hello,
Simply change to this line
JavaScript
minDate: '0',
maxDate: '+2M',


minDate : '0' means , Min date will be today date
and maxDate: +2M means , it will add 2 month with Max date from today date

JSFIDDLE
 
Share this answer
 
v2
Comments
[no name] 13-May-16 3:15am    
Past date is not fixed, it can be 13/03/2016 or 26/12/2015. If it is like past date is always going to be 2 month back wrt to current date then i would have used it what you suggested.
Animesh Datta 13-May-16 3:54am    
Refer :
Link1
Link2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900