Gothic Online Forums
Function getDayCountBetweenDates basing on Julian date. - Printable Version

+- Gothic Online Forums (https://archive.gothic-online.com)
+-- Forum: Scripting (English) (https://archive.gothic-online.com/forum-11.html)
+--- Forum: Resources (https://archive.gothic-online.com/forum-14.html)
+---- Forum: Scripts (https://archive.gothic-online.com/forum-17.html)
+---- Thread: Function getDayCountBetweenDates basing on Julian date. (/thread-2337.html)



Function getDayCountBetweenDates basing on Julian date. - Mattwell - 06.02.2018

Hi, I wrote short day counter between dates basing on Julian date algorithm.

Function returns the difference of days between dates.

USEFUL FOR PREMIUM ACCOUNTS OR ANOTHER THINGS

Code:
function getDayCountBetweenDates(d1d,d1m,d1y,d2d,d2m,d2y)
{
    local date1 = (1461 * (d1y + 4800 + (d1m - 14)/12))/4 + (367 * (d1m - 2 - 12 * ((d1m - 14)/12)))/12 - (3 * ((d1y + 4900 + (d1m - 14)/12)/100))/4 + d1d - 32075;
    
    
    local date2 = (1461 * (d2y + 4800 + (d2m - 14)/12))/4 + (367 * (d2m - 2 - 12 * ((d2m - 14)/12)))/12 - (3 * ((d2y + 4900 + (d2m - 14)/12)/100))/4 + d2d - 32075;
    
    if(date2 > date1)
    {
        return date2 - date1;
    }
    else
    {
        return date1 - date2;
    }
    
}

Arguments: 

- d1d (int): day of first date
- d1m (int): month of first date
- d1y (int): year of first date

- d2d (int): day of second date
- d2m (int): month of second date
- d2y (int): year of second date