Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am using jquery datetimepicker.

i am able to disable time before current time by using following code.

$("#startDate").datetimepicker({
     dayOfWeekStart: 1,
     minDate: 0,

     format: 'd/m/Y H:i',
     formatTime: 'H:i',
     formatDate: 'd/m/Y',
     startDate: currentDateTime,
     ampm: true,

 });


I am having two controls. Start date and End date.
condition:
when user select any date time, value of EndDate will be a day and half an hour ahead.
e.g. if startdate is 11-05-2016 18:00 then
endDate will be 12-05-2016 18:30 (user will not be able to select previous time wrt to endDate time i.e. disable time upto 18:00)

I have achieved above functionality but fails to disable time.
I have used moment js to format date.

What I have tried:

var jsDate = moment($("#JobDate").val(), 'DD-MM-YYYY HH:mm'); 
var minimum = function(jsDate){
       if(jsDate.getMinutes()==0){
         this.setOptions({
            minTime : jsDate.getHours()+":"+(parseInt(jsDate.getMinutes())+33),
            });
       }
       else{
         this.setOptions({
            minTime : (parseInt(jsDate.getHours())+1)+":00",
            });
         }
     };

$("#EndDate").datetimepicker({
     startDate:datetime1,
     onChangeDateTime:minimum,
     onShow:minimum,
 });
var dt = new Date(jsDate.add(1,'days'));
 $("#startDate").val(dt.toString("DD-MM-YYYY HH:mm");


from jquery datetime tutorial i tried above code but it's not working.

if I'm uses minTime : 0 then it is disabling previous time wrt to current time. and that is perfactly fine in the case of startDate. When i try to disable previous time wrt to specific time(i.e.disable time from startDate's selected time for EndDate) as shown above, its not working.

What's wrong with the code?
Posted
Comments
Prateek Dalbehera 21-May-16 12:58pm    
I haven't used datetimepicker but can suggest you to use Moment.js for time related stuffs, here, what you can do is store start time in a moment variable and when user selects endtime compare that value with prevoiusly stored variable to do the validations... Just my idea, you can try...

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