Hi Divakaran N,
Thanks for contacting Syncufsion support.
We understood your requirement to find the number days difference between two DateTime values selected in Datetime picker.
You can achieve this requirement as explained in the below code block.
[App.Component.html]
Start Date
<input id="start" type="text" ej-datetimepicker (ejchange)="onChange($event)"/>
<!-- Bind Change event in Datetimepicker -->
End Date
<input id="end" type="text" ej-datetimepicker (ejchange)="onChange($event)"/>
<!-- Bind Change event in Datetimepicker -->
Now in the Change event of Datetimepicker, you need to find the difference between the selected date and shown in the below code.
[App.Component.TS]
export class DateComponent {
public startDate: Date;
public EndDate: Date;
public dayCount: number;
public onChange(e){
if(e.target.id == "end"){
this.EndDate = new Date(e.value);
this.EndDate.setHours(0,0,0,0); // Reset time to midnight of the day
}
else if(e.target.id == "start"){
this.startDate = new Date(e.value);
this.startDate.setHours(0,0,0,0); // Reset time to midnight of the day
}
if(!!this.startDate && !!this.EndDate){
var diff = Math.abs(this.EndDate.getTime() - this.startDate.getTime()); // Get Timestamp by using getTime method
this.dayCount = Math.ceil(diff / (1000 * 3600 * 24));
alert(this.dayCount);
}
}
We have prepared a sample based on your requirement. Please download it from the below link and rune the below command to see the output.
Command:
1. npm install
2. npm start
Please let us know if you have any further concerns.
Regards,
Deepa L.