Search results

Date Range in Angular Calendar component

30 Sep 2022 / 1 minute to read

You can restrict the user to select the date from a specified range of dates by utilizing the min and max properties. Always the min date has to be lesser than the max date.

The below example allows you to select a date within a range from 7th to 27th days in a month.

Copied to clipboard
import { Component } from '@angular/core';

    selector: 'app-root',
    template: `
        <!--Sets the value, min and max -->
        <ejs-calendar [value]='dateValue' [min]='minDate' [max]='maxDate'></ejs-calendar>
export class AppComponent {
    public today: Date = new Date();
    public currentYear: number =;
    public currentMonth: number =;
    public currentDay: number =;
    public dateValue: Object = new Date(new Date().setDate(14));
    public minDate: Object = new Date(this.currentYear, this.currentMonth, 7);
    public maxDate: Object =  new Date(this.currentYear, this.currentMonth, 27);
    constructor() {
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
//Syncfusion ej2-angular-calendars module
import { CalendarModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';

 * Module
    imports: [
        CalendarModule //declaration of ej2-angular-calendars module into NgModule
    declarations: [AppComponent],
    bootstrap: [AppComponent]
export class AppModule { }
Copied to clipboard
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. Or else, if the value is out of specified date range and less than min date, value property will be updated with min date or the value is higher than max date, value property will be updated with max date.