So im trying to figure out how I can "Properly" separate the dates im getting from the Date range selector.
I've managed to separate them into a start and end value but Id need to more then likely use some kind of regex to separate the dates into a D/M/Y because I have 3 variables I need to fill as later on I need to do calculations with the years and one value is terrible for that. Curious if anyones got any ideas about this
Outputs:
1/1/2021 || 1/8/2021
<mat-form-field appearance="fill">
<mat-label>Enter a date range</mat-label>
<mat-date-range-input [formGroup]="range" [rangePicker]="picker">
<input style="position: relative;" #Startz matStartDate formControlName="start" placeholder="Start date">
<input style="position: relative;" #Endz matEndDate formControlName="end" 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-error *ngIf="range.controls.start.hasError('matStartDateInvalid')">Invalid start date</mat-error>
<mat-error *ngIf="range.controls.end.hasError('matEndDateInvalid')">Invalid end date</mat-error>
</mat-form-field>
<div class="">
<input type="text" class="" placeholder="info" #info required>
</div>
<button style="margin-right:10px;" type="button" class="btn googleBtn" value="Log In" (click)="createEntry(Startz.value, Endz.value, info.value)">Create Entry</button>
createEntry(startDate, endDate, info: string){
alert(startDate + endDate);
}
export class Entry {
id: string;
surname: string;
color: string;
startDate: Startdate;
endDate: Enddate;
info: string;
status: boolean;
}
export class Startdate{
day: number;
month: number;
year: number;
}
export class Enddate{
day: number;
month: number;
year: number;
}
This is what ive done so far but there should surely be a better solution for this:
var value = startDate;
var day = value.substring(0,1);
var month = value.substring(2,3);
var year = value.substring(4,8);
var str = "{Day:" + day + ",month:" + month + ",year:" + year + "}";
alert(str);
The issue with this way is that asoon as u end up with double digit days/months ect it breaks