Calculate future date by days.
#1

Hello,

My question is does somebody have a function that calculates a future date, exampe;
Today - 22-05-2012
Days - 20
New date (by function) - 11-06-2012
I created this:
pawn Код:
new Year, Month, Day, MaxDays,expirestamp;
            getdate(Year, Month, Day);
            expirestamp = gettime() + 92 * 1 * 24 * 60 * 60 * 1000;
            Month += 3;
            switch(Month)
            {
                case 1: MaxDays = 31;
                case 2: MaxDays = 28;
                case 3: MaxDays = 31;
                case 4: MaxDays = 30;
                case 5: MaxDays = 31;
                case 6: MaxDays = 30;
                case 7: MaxDays = 31;
                case 8: MaxDays = 31;
                case 9: MaxDays = 30;
                case 10: MaxDays = 31;
                case 11: MaxDays = 30;
                case 12: MaxDays = 31;

            }
            if(Day > MaxDays)
            {
                Day -= MaxDays;
                Month++;
                if(Month > 12)
                {
                    Month = 1;
                    Year++;
                }
            }
            format(newdate,26,"%02d/%02d/%d",Day,Month,Year);
But it fails when you add more then 31 days.
It only works for 1 month into the future.
If I want to edit it for more it will be alot of code, so I hope somebody already got a faster and smaller function for this?

[EDIT] a function to convert unix timestamp to a date string is also good!!
Reply


Messages In This Thread
Calculate future date by days. - by Roel - 22.05.2012, 18:07
Re: Calculate future date by days. - by Roel - 22.05.2012, 18:21

Forum Jump:


Users browsing this thread: 1 Guest(s)