0

I'm using DateTimePicker jQuery plugin by XDSoft, please check below image

Screenshot

My requirement is that, if i selected current date,(9th Nov, 2015) then the time from time picker should show 6hrs add to current time...

I mean, in above image current Date is selected... and current time is 12.00 but i want that 12.00 & above time should be disable..

How can we do that..??

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
Dhawal Mhatre
  • 435
  • 2
  • 8
  • 28

1 Answers1

1

Based on XDSoft DateTimePicker documentation, here's what can be done:

var logic = function( currentDateTime ){

    var d1 = new Date();

    // Check that it's today, so we need to restrict time chooser
    if (currentDateTime.getDate() == d1.getDate() && currentDateTime.getMonth() == d1.getMonth())
    {
        // Adding six hours
        d1.setHours ( d1.getHours() + 6 );    

        // Creating 'HH:MM' string
        var defaultTime = (d1.getHours() < 10 ? "0" : "") + d1.getHours() + ":" + (d1.getMinutes() < 10 ? "0" : "") + d1.getMinutes();

        // Enforce time restriction
        // ('this' is jquery datetimepicker object)
        this.setOptions({
            minTime : defaultTime,
            defaultTime : defaultTime
        });
    }
    else
    {
        // Lift time restriction if selected day is not today
        this.setOptions({
            minTime : false,
            defaultTime : false
        });
    }
};

// Initiate datepicker with custom logic
$('#datetimepicker').datetimepicker({
    onChangeDateTime:logic,
    onShow:logic
});    

Adding 6 hours solution based on: https://stackoverflow.com/a/13034220/2715393

Community
  • 1
  • 1
Vaviloff
  • 16,282
  • 6
  • 48
  • 56
  • just want to know, is it possible to show time in textbox on timer click.. because now when we click on date it show current time with date in textbox..?? – Dhawal Mhatre Dec 04 '15 at 14:03
  • Not sure what you mean. In the example above when you click on timer, selected date and time are then set in the input box, from which datetimepicker had been called. – Vaviloff Dec 06 '15 at 03:44
  • i mean to say that, if current time is 18.02 and i click on current date, in the input box its show current date & current time, instead of current date & time + 6 hrs.. – Dhawal Mhatre Dec 07 '15 at 13:44
  • @DhawalMhatre Could you look at this question I asked similar to this one. http://stackoverflow.com/questions/36265386/add-6-hours-if-outside-of-business-hours-to-datetimepicker minTime is only working of '0' – theRyanMark Mar 28 '16 at 16:20