Trying to figure out how to change the format of the selected dates to something like "08/24/2016"
What I keep getting is something like this:
Wed Aug 24 2016 00:00:00 GMT-0400 (Eastern Daylight Time)
Anyone know how to change it?
Applying the DatePipe to your model should help.
[(ngModel)]="something" is a two-way binding. So it's actually trying to assign the new value back to policy.effective | date: 'shortDate' which doesn't make sense.
You effectively want a one-way binding since nothing can be written TO effectiveDate. [ngModel]="effectiveDate" (no parenthesis) would be more appropriate.
Sorry to open this thread again. But did anyone find a way to format the date using reactive forms?
@washingtonphp As a workaround I use a separate input that toggles the datepicker and shows the formatted date. I then set the bsDatepicker field to hidden:
<input
type="text"
class="form-control"
bsDatepicker
#newDateControl
[style.visibility]="'hidden'"
[formControl]="newOptionDate">
<input
type="text"
class="form-control"
(focus)="newDateControl.toggle()"
[value]="newOptionDate.valueChanges | async | date:'mediumDate'">
Is there any way to store only MM/dd/yyyy in my ngModel using new bsDatepicker? Than the full date.
I did this.
Two way binding
name="bsDatepicker" class="form-control"
#dp="bsDatepicker" bsDatepicker placeholder="MM-dd-yyyy">
on my submit function I change the format of my model value to MM/dd/yyyy ie 01/01/2018
const date = new Date(
this.pilot.dob = moment(date).format('MM/DD/YYYY');
app.component.ts
import {formatDate} from '@angular/common';
submit() {
const date = new Date(this.date);
this.date = formatDate(date, 'MM/dd/yyyy', 'en');
console.log(this.date);
}
Most helpful comment
Sorry to open this thread again. But did anyone find a way to format the date using reactive forms?