Date time range in Angular Datetimepicker component

17 Nov 20223 minutes to read

DateTimePicker provides an option to select a date and time value within a specified range by using the min and maxproperties.
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.

import { Component } from "@angular/core";

  selector: 'app-root',
  template: `<ejs-datetimepicker [value]='date' [min]='minDate' [max]='maxDate'></ejs-datetimepicker>`
export class AppComponent {
  public today: Date = new Date();
  public currentYear: number =;
  public currentMonth: number =;
  public currentDay: number =;
  public currentHour: number =;
  public currentMinute: number =;
  public currentSecond: number =;
  public date: Date = new Date(new Date().setDate(14));
  public minDate: Date = new Date(this.currentYear,this.currentMonth,7,0,0,0);
  public maxDate: Date = new Date(this.currentYear,this.currentMonth,27,this.currentHour,this.currentMinute,this.currentSecond);
  constructor() {}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { DateTimePickerModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';

 * Module
    imports: [
    declarations: [AppComponent],
    bootstrap: [AppComponent]
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';


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.