Date time range in EJ2 JavaScript Datetimepicker control

16 Jun 20233 minutes to read

DateTimePicker provides an option to select a date and time value within a specified range by using the min
and max properties. Always the min value has to be lesser than the max value.

When the min and max properties are configured and the selected datetime value is out-of-range or invalid, then the model value will be set to out of range datetime value or null respectively with highlighted error class to indicates the datetime is out of range or invalid.

The value property depends on the min/max with respect to strictMode property.

The below example allows selecting a date within the range from 7th to 27th day in a month.

    var today = new Date();
    var currentYear = today.getFullYear();
    var currentMonth = today.getMonth();
    var currentDay = today.getDate();
    var datetimepicker = new ej.calendars.DateTimePicker({
        min: new Date(currentYear, currentMonth, 7, 10),
        max: new Date(currentYear, currentMonth, 27, 22, 30),
        value: new Date(currentYear, currentMonth, 14, 10, 30),
        placeholder: 'Choose a datetime'
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 DateTimePicker control</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="styles.css" rel="stylesheet">
    <!--style reference from the DateTimePicker component-->
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
<script src="" type="text/javascript"></script>
<script src="" type ="text/javascript"></script>

    <div id="container">
        <input id="element" type="text">

var ele = document.getElementById('container');
if(ele) { = "visible";
<script src="index.js" type="text/javascript"></script>

 If the value of min or max properties changed through code behind, then you have to update the value property to set within the range.