(SOLVED) TypeScript – Get difference between two dates in days

if you need to get the difference between two dates in days. you can use this function :

   dayDiff(d1:Date, d2:Date)
    var diff = Math.abs(date1.getTime() - date2.getTime());
    var diffDays = Math.ceil(diff / (1000 * 3600 * 24)); 
    return diffDays;

if you are using the date as a String you can have this error getTime() is not a function ! so if you have this error try this solution

Marwen Mselmi
Author: Marwen Mselmi

Founder of Javatuto.com, love Java and open source stuff. Follow me on Linkedin.

Leave a comment