Click here to Skip to main content
15,390,197 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please can anyone provide a method to calculate the difference between 2 hijri dates

start date 01/10/1429

End Datem 04/23/1436

Output
7Y 3M 14D

What I have tried:

function CalculateDate() {
       var startDate = "01/10/1429";
       var endDate = "04/23/1436";

       var sdt = new Date(startDate);
        var edt = new Date(endDate);
       var difdt = new Date(edt - sdt);
       const diffTime = Math.abs(sdt - edt);
       const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
       TotalDays.SetText(diffDays + " Total Days");    <-- total days are more than actual calendar days

        alert((difdt.toISOString().slice(0, 4) - 1970) + "Y " + (difdt.getMonth()) + "M " + (difdt.getDate() - 1) + "D");
   }
Posted
Updated 21-Dec-21 21:55pm
Comments
BillWoodruff 22-Dec-21 4:10am
   
The date data you show here are not Hjri dates ? Is the problem how to convert to Hijri date ?
$ultaNn 23-Dec-21 4:51am
   
yes the problems if for hijri dates calculation

1 solution

Look at HijriCalendar Class (System.Globalization) | Microsoft Docs[^], especially the ToDateTime() methods.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900