Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: DatePicker IMyOption disableSince Option

Jan Louw pro asked 5 years ago


Hi,

Using the DatePicker disableSince options and trying to set it to current date parameters, results in wrong date.

Code Snippet:

myDatePickerOptions: IMyOptions;

constructor(private cdRef: ChangeDetectorRef, private dbsrv: DbService, public datepipe: DatePipe) {}

 ngOnInit() {
   this.myDatePickerOptions = {
     closeAfterSelect: true,
     showClearDateBtn: false,
     disableSince: { year: this.nowDate.getFullYear(), month: this.nowDate.getMonth(), day: this.nowDate.getDay() }
   };
   console.log('DatePicker Options: %s', JSON.stringify(this.myDatePickerOptions));
   console.log('Date: %s', JSON.stringify(this.nowDate));
 }

Console Output:

DatePicker Options: {"closeAfterSelect":true,"showClearDateBtn":false,"disableSince":{"year":2019,"month":7,"day":3}}

Date: "2019-08-28T12:46:50.031Z"

Any idea why the month and day is incorrect?

Regards


Jan Louw pro commented 5 years ago

Hi,

Being the first time looking at date/time processing in Javascript / Typescript, I've realized my confusion around the getMonth() and getDay()/getDate() function calls on Date object. Apologies for adding this ... :( . Regards


Arkadiusz Idzikowski staff answered 5 years ago


Glad it works now. If anyone will have similiar problem in the future, to correct way is to add +1 to the getMonth result (because the getMonth() method returns the month from 0 to 11) and to use getDate method instead of getDay to get the day number.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 8.1.1
  • Device: Na
  • Browser: Na
  • OS: Ubuntu 16:04
  • Provided sample code: No
  • Provided link: No