| 
 | 1 | +---  | 
 | 2 | +title: Dynamically Setting Min Date and Time for Kendo UI DateTimePicker  | 
 | 3 | +description: Learn how to dynamically set the minimum date and time for a Kendo UI DateTimePicker based on another DateTimePicker's selection.  | 
 | 4 | +type: how-to  | 
 | 5 | +page_title: How to Set Min Date and Time Based on Another DateTimePicker's Selection in Kendo UI  | 
 | 6 | +slug: dynamically-set-min-date-time-kendo-datetimepicker  | 
 | 7 | +tags: kendo-ui, datetimepicker, min-date, setoptions, javascript  | 
 | 8 | +res_type: kb  | 
 | 9 | +ticketid: 1674797  | 
 | 10 | +---  | 
 | 11 | + | 
 | 12 | +## Description  | 
 | 13 | + | 
 | 14 | +When using two [Kendo UI for jQuery DateTimePicker](https://docs.telerik.com/kendo-ui/api/javascript/ui/datetimepicker) components for start and end date selections, it's necessary to update the minimum selectable date and time of the end date picker based on the selection in the start date picker. This ensures that the end date cannot precede the start date.   | 
 | 15 | + | 
 | 16 | +This knowledge base article also answers the following questions:  | 
 | 17 | +- How to dynamically change the minimum date of a DateTimePicker based on another DateTimePicker's value?  | 
 | 18 | +- How to use the setOptions method to update DateTimePicker settings?  | 
 | 19 | +- How to synchronize two DateTimePicker controls to ensure logical date and time selection?  | 
 | 20 | + | 
 | 21 | +## Solution  | 
 | 22 | + | 
 | 23 | +To dynamically set the minimum date and time for the end date DateTimePicker based on the start date DateTimePicker's selection, use the `change` event of the start date DateTimePicker. Within this event, retrieve the selected date and time, and then use the `setOptions` method to update the minimum date (`min`) and start time (`startTime`) of the end date DateTimePicker.  | 
 | 24 | + | 
 | 25 | +Here's an example of how to implement this:  | 
 | 26 | + | 
 | 27 | +```javascript  | 
 | 28 | +// Assuming shiftStart and shiftEnd are your DateTimePicker instances  | 
 | 29 | +shiftStart.kendoDateTimePicker({  | 
 | 30 | +    timeFormat: "HH:mm",  | 
 | 31 | +    format: "dd MMM yyyy HH:mm",  | 
 | 32 | +    min: new Date(vYear, vMonth - 1, vDay, vHour, vMin),  | 
 | 33 | +    interval: 15,  | 
 | 34 | +    change: function() {  | 
 | 35 | +        var startDT = this.value();  | 
 | 36 | +        var year = startDT.getFullYear();  | 
 | 37 | +        var month = startDT.getMonth();  | 
 | 38 | +        var day = startDT.getDate();  | 
 | 39 | +        var vHour = startDT.getHours();  | 
 | 40 | +        var vMin = startDT.getMinutes();  | 
 | 41 | +        shiftEnd.data("kendoDateTimePicker").setOptions({  | 
 | 42 | +            min: new Date(year, month, day, vHour, vMin),  | 
 | 43 | +            startTime: new Date(year, month, day, vHour, vMin)  | 
 | 44 | +        });  | 
 | 45 | +    }  | 
 | 46 | +});  | 
 | 47 | + | 
 | 48 | +shiftEnd.kendoDateTimePicker({  | 
 | 49 | +    timeFormat: "HH:mm",  | 
 | 50 | +    format: "dd MMM yyyy HH:mm",  | 
 | 51 | +    min: new Date(vYear, vMonth - 1, vDay, vHour, vMin),  | 
 | 52 | +    interval: 15  | 
 | 53 | +});  | 
 | 54 | +```  | 
 | 55 | + | 
 | 56 | +This code snippet demonstrates how to configure the `shiftStart` DateTimePicker to update the `shiftEnd` DateTimePicker's `min` and `startTime` options upon a change.   | 
 | 57 | + | 
 | 58 | +## See Also  | 
 | 59 | + | 
 | 60 | +- [Kendo UI DateTimePicker Documentation](https://docs.telerik.com/kendo-ui/api/javascript/ui/datetimepicker)  | 
 | 61 | +- [Kendo UI DateTimePicker setOptions Method](https://docs.telerik.com/kendo-ui/api/javascript/ui/datetimepicker/methods/setoptions)  | 
 | 62 | +- [Example of Synchronizing Two DateTimePickers](https://dojo.telerik.com/dXCVgCOv)  | 
0 commit comments