Calculate days between two dates
#1

Hey everybody.
Once again a sortof easy question.
If i wouldn't be so much confused about dates and stuff, i would have done it by myself, but every try i take definatly fails at the moment. What i want to do is to calculate the amount of days between two dates, like this:

10th August 2010 --> 8th September 2010 --> 20 days

8th September 2010 --> 10th August 2010 --> -20 days

Thanks.
Reply
#2

http://forum.sa-mp.com/showpost.php?...&postcount=980

That should help you a bit.


Im a little to busy to write out exactly how to do it, sorry. I've replied to several topics explaining it already, if you search im sure you'll be able to find one.

Its exactly the same as bench marking with GetTickCount, except you use gettime() (no parameters) and actually store the first value (mysql/dini).
Reply
#3

Alright now i took another try:

pawn Код:
CalculateDaysBetweenDates(d1,m1,y1,d2,m2,y2)
{
    d2-=d1;
    if(y1!=y2)
    {
        while(y1!=y2)
        {
            printf("%i;%i;%i;%i", d2,m1,y1,ddiff);
            ddiff+=days[m1-1];
            m1++;
            if(m1==13)
            {
                y1++;
                m1=1;
            }
            printf("%i;%i;%i;%i", d2,m1,y1,ddiff);
        }
        ddiff+=d2;
        return ddiff;
    }
    else if(y1==y2)
    {
        if(m1!=m2)
        {
            while(m1!=m2)
            {
                printf("%i;%i;%i;%i", d2,m1,y1,ddiff);
                ddiff+=days[m1-1];
                m1++;
                if(m1==13)
                {
                    y1++;
                    m1=1;
                }
                printf("%i;%i;%i;%i", d2,m1,y1,ddiff);
            }
            ddiff+=d2;
            return ddiff;
        }
        else if(m1==m2)
        {
            return d2;
        }
        else return print("Calculation Error");
    }
    else return print("Calculation Error");
}
I think for the beginning this should be enough. It doesn't calculate the gay-februaries correctly, yet, but that won't be that complicated.
#Edit: If anybody doesn't understand the reason why there are so many printf's, it's for me to see if everythign works fine.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)