We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Allow user to select last 6 months

Hello,

Is there anyway to prevent the user from selecting the current and future month while allowing the user to select the last six months from an SFDatePicker?


 <label class="example-label">Report Date</label>

                        <SfDatePicker TValue="DateTime?" Format="MMMM yyyy" Placeholder="Choose a Month" Start="CalendarView.Year" Depth="CalendarView.Year" ShowClearButton="true">

                            <DatePickerEvents TValue="DateTime?" ValueChange="OnChange"></DatePickerEvents>

                        </SfDatePicker>


 public void OnChange(ChangedEventArgs<DateTime?> args)

    {

        DateTime lastDay = new DateTime(args.Value.Value.Year, args.Value.Value.Month + 1, 1).AddDays(-1);

        SelectedValue = lastDay.ToString("dd-MMM-yy");

        this.ODGrid.FilterByColumnAsync("ReportDate", "equal", @SelectedValue);


        var Count = 0;

        var CurrentMonth = CurrentDate.Value.Month;


    }

Regards



1 Reply 1 reply marked as answer

UD UdhayaKumar Duraisamy Syncfusion Team December 6, 2022 07:41 AM UTC

You can limit the user's selection to the last six months by using the Min and Max properties. Please refer to the shared code snippet and documentation for more information.


 

<SfDatePicker TValue="DateTime?" Format="MMMM yyyy" Placeholder="Choose a Month" Min='@MinDate' Max='@MaxDate' Start="CalendarView.Year" Depth="CalendarView.Year" ShowClearButton="true">

    <DatePickerEvents TValue="DateTime?" ValueChange="OnChange"></DatePickerEvents>

</SfDatePicker>

 

@code {

    public DateTime MinDate { get; set; } = new DateTime(DateTime.Now.Year, 7, 01);

    public DateTime MaxDate { get; set; } = new DateTime(DateTime.Now.Year, 12, 31);

}


Documentation : https://blazor.syncfusion.com/documentation/datepicker/date-range


Marked as answer
Loader.
Up arrow icon