We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

We need Onchange event for EJ1 DatetimePicker for angular 4 with Typescript

Hi team ,

We have project developed by Angular 4 with typescript and web api using EJ1 Components.

In that application , I have EJ1Date timepicker for Start Date and End Date in Dialog , My scenorio is calculate the Days difference between Start Date and End Date based on Changing the Date .

Please give some samples for me asap . We are already end of the Development Statge. 

Divakaran N 

1 Reply

DL Deepa Loganathan Syncfusion Team January 8, 2019 12:15 PM UTC

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.  
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.  
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));  
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. 
1.      npm install 
2.      npm start 
Please let us know if you have any further concerns.  
Deepa L. 

Live Chat Icon For mobile
Up arrow icon