Counting back days
#1

Hello,

I am creating a function which calculates how much days there are between two dates. Here it is:
pawn Код:
GetDateDifference(date1[], date2[])
{

    new Float:difference = 0.0, splitvar[3][5];
    Split(date1, splitvar, '/');
    new day = strval(splitvar[0]);
    new month = strval(splitvar[1]);
    new year = strval(splitvar[2]);
    Split(date2, splitvar, '/');
    new differenceday = strval(splitvar[0]);
    new differencemonth = strval(splitvar[1]);
    new differenceyear = strval(splitvar[2]);
    for(new i = 0; day != differenceday; i++)
        {
        if(day < differenceday)
            {
            difference += 1.00;
            differenceday -= 1;
            }
        else if(day > differenceday)
            {
            difference += 1.00;
            differenceday += 1;
            }
        }
    for(new i = 0; month != differencemonth; i++)
        {
        if(month < differencemonth)
            {
            difference += 30.43750137090681;
            differencemonth -= 1;
            }
        else if(month > differencemonth)
            {
            difference += 30.43750137090681;
            differencemonth += 1;
            }
        }
    for(new i = 0; year != differenceyear; i++)
        {
        if(year < differenceyear)
            {
            difference += 365.25;
            differenceyear -= 1;
            }
        else if(year > differenceyear)
            {
            difference += 365.25;
            differenceyear += 1;
            }
        }
    printf("%f", difference);
    return floatround(difference, floatround_tozero);
}
This returns 7194 days if I calculate the difference between 14/02/1994 and 25/10/2013, however several websites like this one all say the difference is 7193 days. I calculated the number that should be added per day/month/year like this:
Once every 4 years there is a year with 366 days, so if you give every year 0.25 days extra every year has 365.25 days, if you do 365.25/12 you got the average days per month which is 30.43750137090681 days.

If someone could explain to me why the piece of code prints 7194.250000000 and rounded (Obviously.) gives 7194 that would be much appreciated.

Best regards,
Jesse
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)