152
rated 0 times
[
155]
[
3]
/ answers: 1 / hits: 23098
/ 5 Years ago, tue, march 12, 2019, 12:00:00
hi i am using ngbDatePicker and my format is YYYY-MM-DD
and i am trying to change it but cant seem to change the format to MM/DD/YYYY.
here is my html code
<div class=form-group datepicker>
<label for=dob>Date of Birth*</label>
<div class=row input-group>
<input
ngbDatepicker
#d=ngbDatepicker
#dobF=ngModel
class=form-control input-underline input-lg
id=dob
[(ngModel)]=dateOfBirth
placeholder=mm-dd-yyyy
name=dp
[ngClass]={
invalid:
(dobF.value === null || isString(dobF.value) || futureDate) && dobF.touched
}
required
/>
<div class=input-group-append>
<button
class=btn btn-outline-secondary calendar
(click)=d.toggle()
type=button
></button>
</div>
</div>
<div
*ngIf=
(dobF.value === null || isString(dobF.value) || futureDate) && dobF.touched
class=error
>
Please enter a valid date of birth.
</div>
</div>
here is my ts file code
public dateOfBirth: { year: number; month: number; day: number };
public currentDate = moment().format(YYYY-MM-DD);
constructor(
private config: NgbDatepickerConfig
) {
// customize default values of datepickers used by this component tree
const currentDate = new Date();
const day = currentDate.getDate();
const month = currentDate.getMonth() + 1;
const year = currentDate.getFullYear();
this.config.minDate = {year: 1900, month: 1, day: 1};
this.config.maxDate = {year, month, day};
this.config.outsideDays = hidden;
}
ngOninit() {
this.subscriptions[patient] = this.store
.select(patient)
.subscribe(data => {
this.patient = Object.assign({}, this.patient, data);
const dob = this.patient.Dob ? this.patient.Dob.split(-) : null;
dob !== null
? (this.dateOfBirth = {
year: Number(dob[0]),
month: Number(dob[1]),
day: Number(dob[2])
})
: (this.dateOfBirth = null);
});
}
ngAfterContentChecked() {
let currentDateObject = this.currentDate.split(-);
this.dobYear = Number(currentDateObject[0]);
this.dobMonth = Number(currentDateObject[1]);
this.dobDay = Number(currentDateObject[2]);
if (this.dateOfBirth) {
this.futureDate = this.dateOfBirth.year > this.dobYear || (this.dateOfBirth.year == this.dobYear && this.dateOfBirth.month > this.dobMonth)
|| (this.dateOfBirth.year == this.dobYear && this.dateOfBirth.month == this.dobMonth && this.dateOfBirth.day > this.dobDay);
}
}
i cannot seem to find any help to change the format.
how can i change the format from YYYY/DD/MM toMM/DD/YYYY.
is there any help thanks
More From » angular