Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
angular date range +2 date logic (excluding weekends)

Currently I have a mat date picker range. The logic is the min date on the calendar that the user can select is + 2 days so for example date today is 20(july 20, 2022) then the min date is 22(july 22, 2022) because it is + 2.

But if the next 2 days are weekends for example our current date is let us say today is 22(july 22, 2022) if you look at the calendar 23 and 24 are weekends so it must be excluded so +2 would start from 22(july 22, 2022) and 25(july 25, 2022) so the min date would be 26(july 26, 2022).

How would we handle this logic on a date picker ?

#https://stackblitz.com/edit/angular-byrmnt-setsza?file=src%2Fapp%2Fdate-range-picker-overview-example.ts,src%2Findex.html,src%2Fapp%2Fdate-range-picker-overview-example.html

#html

<mat-form-field>
  <mat-label>Enter a date range</mat-label>
  <mat-date-range-input [rangePicker]="picker" [dateFilter]="weekendsDatesFilter">
    <input matStartDate matInput placeholder="Start date" >
    <input matEndDate matInput placeholder="End date">
  </mat-date-range-input>
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-date-range-picker #picker></mat-date-range-picker>
</mat-form-field>

#ts

export class DateRangePickerOverviewExample {
  currentDate = new Date();

  ngOnInit(): void { 
    this.currentDate = new Date(this.currentDate.setDate(this.currentDate.getDate() + 2));
  }

  weekendsDatesFilter = (d: Date): boolean => {
    const day = d.getDay();
    /* Prevent Saturday and Sunday for select. */
    return day !== 0 && day !== 6;
  };
}
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Can you please check this click here? I hope this will work for you.

 import { Component } from '@angular/core';
    
    @Component({
      selector: 'date-range-picker-overview-example',
      templateUrl: 'date-range-picker-overview-example.html',
      styleUrls: ['date-range-picker-overview-example.css'],
    })
    export class DateRangePickerOverviewExample {
      currentDate = new Date();
    
      ngOnInit(): void {
        this.currentDate = new Date(
          this.currentDate.setDate(this.currentDate.getDate() + 2)
        );
        !this.weekendsDatesFilter(this.currentDate) && this.weekendsHandler();
      }
    
      weekendsDatesFilter = (d: Date): boolean => {
        const day = d.getDay();
        /* Prevent Saturday and Sunday for select. */
        return day !== 0 && day !== 6;
      };
      weekendsHandler() {
        this.currentDate = new Date(
          this.currentDate.setDate(this.currentDate.getDate() + 1)
        );
        !this.weekendsDatesFilter(this.currentDate) && this.weekendsHandler();
      }
    }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!