I would like to choose a date, then convert it to the last day of the month and display it in the datpicker? Has anyone done something like that already? I have been struggling for two days and I still have not found the problem solved. The problem concerns the display itself and in the datepicker. If anyone has an idea, I am asking for an example of virtue.
Asked
Active
Viewed 33 times
0
-
It depends on which Datepicker you are using. – Francis Ngueukam May 11 '18 at 11:51
2 Answers
1
I would recommend you to use native datepickers (html) to make your life easier. Once you have it, it will run everywhere (desktop, web or phone apps)
Click here to see a working example with datepickers on JSFiddle
const $origin_day = document.querySelector('label:first-of-type > input')
const $last_day = document.querySelector('label:last-of-type > input')
$origin_day.onchange = () => {
if (!$origin_day.value) return;
const date = new Date($origin_day.value)
$last_day.value = new Date(date.getFullYear(), date.getMonth() + 1, 1)
.toISOString().slice(0, 10)
}

gengns
- 1,573
- 14
- 23
0
As you can basically write in plan JS you should take a look at this Thread on how to get last day of previous month
You didn't tell us which datepicker you are using but assuming it's Material Datepicker, using Reactive forms, it goes like this:
JS: this.editForm.controls['dateTo'].setValue(yourDate);
HTML:
<input matInput [matDatepicker]="pickerTo" placeholder="Choose a date" id="cmp_dateEndField"
[formControl]="dateTo">
<mat-datepicker-toggle matSuffix [for]="pickerTo"></mat-datepicker-toggle>
<mat-datepicker #pickerTo></mat-datepicker>

theriddle2
- 398
- 3
- 9
-
I use the whole project https://www.npmjs.com/package/angular2-datepicker – Kamil May 11 '18 at 11:50