SA-MP Forums Archive
How can i check the days between 2 dates? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How can i check the days between 2 dates? (/showthread.php?tid=259183)



How can i check the days between 2 dates? - tal_peretz - 03.06.2011

i fixed it, thanks anyway.


Re: How can i check the days between 2 dates? - Donya - 03.06.2011

pawn Code:
stock CalcDate(&year, &month, &day, extradays)
{
    getdate(year, month, day);
    day += extradays;
    // suppose day = 27 and extradays = 8
    // day is now 35

    switch(month)
    {
        case 1, 3, 5, 7, 8, 10, 12: // 31 day months
        {
            if(day > 31 )
            {
                if(month == 12)
                {
                    month = 1;
                    year++;
                }
                else
                {
                    month++;
                }
                day -= 31; // day is now 4
            }
        }
        case 4, 6, 9, 11: // 30 day months
        {
            if(day > 30 )
            {
                month++;
                day -= 30;
            }
        }
        case 2: // february
        {
            if((day + extradays) > 28 )
            {
                month++;
                day -= 28;
            }
        }
    }
}



Re: How can i check the days between 2 dates? - tal_peretz - 03.06.2011

no man... i need to write 2 date, and it's return me the days between them, no the days from now.

edit -

i did it alone thanks anyway


Re: How can i check the days between 2 dates? - jameskmonger - 03.06.2011

So why not post how you did it and help people?


Re: How can i check the days between 2 dates? - tal_peretz - 03.06.2011

PHP Code:
stock DatesTime(Start[], End[],&offest)
{
    new 
dtmp[256], idx1idx2;
    
dtmp strtok(Startidx1'.');
    new 
StartDay strval(dtmp);
    
dtmp strtok(Startidx1'.');
    new 
StartMonth strval(dtmp);
    
dtmp strtok(Startidx1'.');
    new 
StartYear strval(dtmp);
    
dtmp strtok(Endidx2'.');
    new 
EndDay strval(dtmp);
    
dtmp strtok(Endidx2'.');
    new 
EndMonth strval(dtmp);
    
dtmp strtok(Endidx2'.');
    new 
EndYear strval(dtmp);
    new 
init_date mktime(12,0,0,StartDay,StartMonth,StartYear);
    new 
dest_date mktime(12,0,0,EndDay,EndMonth,EndYear);
    
offest dest_date init_date;
    
offest floatround(offest/60/60/24floatround_floor);
    return 
1;

enjoy.