Date Problem (+rep)
#1

Hello Guys.I get new problem with my passport system.I maked a passport system and right now i dont know how can i make ex. today is 30 and when i get my passport from lspd he tell me Your passport will be done at 35/11/2014 how can i make to say ex will be done at 05/11/2014 from this day +5 days and check if is new month but at me he say 35/11/2014 can anyone help me ? Thanks

pawn Код:
if(Gotovepasosot[playerid] == 1)
                {
                    PlayerInfo[playerid][pPasos] = 1;
                    SCMF(playerid, COLOR_WHITE, "{00C0FF}[INFO]{FFFFFF} Go podignavte vasiot pasos koj sto trae do %d/%d/%d %d:%d",istekuvanjeden,vadenjemesec,vadenjegodina,vadenjesaat,vadenjeminuta);
                    Gotovepasosot[playerid] = 1;
                    Cekazapasos[playerid] = 0;
                    PlayerInfo[playerid][pVadenjeDen] = vadenjeden;
                    PlayerInfo[playerid][pVadenjeMesec] = vadenjemesec;
                    PlayerInfo[playerid][pVadenjeGodina] = vadenjegodina;
                    PlayerInfo[playerid][pVadenjeSaat] = vadenjesaat;
                    PlayerInfo[playerid][pVadenjeMinuta] = vadenjeminuta;
                    PlayerInfo[playerid][pIstekuvanjeDen] = istekuvanjeden;
                    PlayerInfo[playerid][pIstekuvanjeMesec] = vadenjemesec;
                    PlayerInfo[playerid][pIstekuvanjeGodina] = vadenjegodina;
                    PlayerInfo[playerid][pIstekuvanjeSaat] = vadenjesaat;
                    PlayerInfo[playerid][pIstekuvanjeMinuta] = vadenjeminuta;
                    OnPlayerUpdate(playerid);
                }
Код:
VadenjeDen = GettingDay
VadenjeMesec= GettingMonth
VadenjeGodina = GettingYear
VadenjeSaat = GettingHour
VadenjeMinuta = GettingMinute
IstekuvanjeDen = LeakageDay
IstekuvanjeMesec = LeakageMonth
IstekuvanjeGodina = LeakageYear
IstekuvanjeSaat = LeakageHour
IstekuvanjeMinuta = LeakageMinute
Gotovepasosot = Passportisdone
Cekazapasos = Waitingforpassport
pPasos = pPassport
Thanks for visiting this thread, i hope anyone can help me and i will give him a rep++.Best regrads
Reply
#2

hare's example how to get date
pawn Код:
new Str[64];
new day, month, year;
getdate(day, month, year);
format(Str, sizeof(Str), "%02d/%02d/%02d", day, month, year);
SendClientMessage(playerid, 0xFFFF00FF, Str);
Reply
#3

aha and i need to replace the %d with %02d ??
Reply
#4

yeap
Reply
#5

Quote:
Originally Posted by ScripteRMKD
Посмотреть сообщение
aha and i need to replace the %d with %02d ??
no, you don't have to format it any more cuz it's already been formatted by getdate.

also, "UltraScripter" made a small mistake in the code he posted
Quote:
Originally Posted by UltraScripter
pawn Код:
getdate(day, month, year);
that's just wrong.
the prototype of getdate is as follows
pawn Код:
unsigned int getdate(unsigned int year, unsigned int month, unsigned int day);
//so its actually: year, month, day
his code would produce something like this:
pawn Код:
2014/11/30
here, "day" is actually the year, "month" the month (got that right ^^)
but "year" the day


what you want is to add 5 days to "days" right?
something like this
pawn Код:
new d[3];
    getdate(d[0], d[1], d[2]);
   
    printf("Date: %d/%d/%d",d[2]+5, d[1], d[0]);// +5 for days
it'll print
Date: 35/11/2014
Reply
#6

okey i will try if works rep for you two
Reply
#7

That still will result in dates such as 35/05/2014. You'll need to calculate if it's the next month. Which would require an array with the length of months and also some way to deal with leap years.
Reply
#8

Again not working

pawn Код:
new d[3];
                getdate(d[0], d[1], d[2]);
                if(Gotovepasosot[playerid] == 1)
                {
                    PlayerInfo[playerid][pPasos] = 1;
                    SCMF(playerid, COLOR_WHITE, "{00C0FF}[INFO]{FFFFFF} Go podignavte vasiot pasos koj sto trae do %d/%d/%d %d:%d",d[2]+5,d[1],d[0],vadenjesaat,vadenjeminuta);
                    Gotovepasosot[playerid] = 1;
                    Cekazapasos[playerid] = 0;
                    PlayerInfo[playerid][pVadenjeDen] = d[2];
                    PlayerInfo[playerid][pVadenjeMesec] = d[1];
                    PlayerInfo[playerid][pVadenjeGodina] = d[0];
http://i.imgur.com/tSdqeRm.png
Reply
#9

Because what he posted doesn't change the months. It only adds 5 days. Read what I wrote.
Reply
#10

Can you give me becouse i dont know how can i make it to calculate if its the next month ?
Reply
#11

Quote:
Originally Posted by AnthonyTimmers
Посмотреть сообщение
That still will result in dates such as 35/05/2014. You'll need to calculate if it's the next month. Which would require an array with the length of months and also some way to deal with leap years.
That was my first thought too, but then I came up with this:
pawn Код:
new year, month, day, maxdays;
    getdate(year, month, day);
    printf("Date: %02d/%02d/%d", day, month, year);
    switch(month)
    {
        case 1, 3, 5, 7, 8, 10, 12: maxdays = 31;
        case 4, 6, 9, 11: maxdays = 30;
        case 2: maxdays = ((!(year % 4)) ? (29) : (28));
    }
    if((day += 5) > maxdays) day -= maxdays, month++;
    if(month > 12) month -= 12, year++;
    printf("Date +5 days: %02d/%02d/%d", day, month, year);
Simply replace 'year', 'month' and 'day' with your own variables.

Код:
case 1, 3, 5, 7, 8, 10, 12: maxdays = 31;
		case 4, 6, 9, 11: maxdays = 30;
		case 2: maxdays = ((!(year % 4)) ? (29) : (28));
This says, if month is 1, 3, 5, 7 etc., the maximum days in that month will be 31. This never changes depending on the year.
If the month is 4, 6, 9, 11, the maximum days in that month will be 30. This never changes depending on the year.
If the month is February, we need to check if it's a leap year to determine whether the maximum days will be 28 or 29.
Код:
maxdays = ((!(year % 4)) ? (29) : (28));
Leap years occur every 4 years, so we can simply just see whether the year is divisible by 4 by doing: '!(year % 4)'. Thus we can determine whether it is a leap year or not. This pretty much translates to:
pawn Код:
if(leapyear) maxdays = 29;
else maxdays = 28;
Код:
if((day += 5) > maxdays) day -= maxdays, month++;
If adding 5 days to the number of days is greater than the maximum days in that month, we need to change the month and reset the days.
Код:
if(month > 12) month -= 12, year++;
If we happen to be in December and moving into the next year, this updates the years and resets the months.
Reply
#12

I hope this will work and i repping right now for you Treshold and can you help me with one again think.How can i make example.If now is 11pm hour and +1 hour for passport he say to me Your passport will be done at: 0:25 example how can i make to type done at: 00:25
Reply
#13

fixed with the code, anyone help with the 00:00 hour thanks
Reply
#14

pawn Код:
if(hour > 12) hour -= 12;
Then just display:
pawn Код:
printf("%02d:%02d", hour, day);
Reply
#15

Ok can you help me with one think please.Right now i have bug.I maked if hour is 00:00 and the date is 31/12/2014 i want to say Your passport will be done at: 01/01/2015 at 00:15 but at me say will be done at: 31/12/2014 at 24:15 or 25:15 :@@
Reply
#16

Can you show me your code?
Reply
#17

pawn Код:
new godina, mesec, den, maxdenovi, saat, minuta, sekunda, maxsaati, maxminuti;
                godina = 2014;
                mesec = 12;
                den = 31;
                saat = 23;
                minuta = 10;
                switch(mesec)
                {
                    case 1, 3, 5, 7, 8, 10, 12: maxdenovi = 31;
                    case 4, 6, 9, 11: maxdenovi = 30;
                    case 2: maxdenovi = ((!(godina % 4)) ? (29) : (28));
                }
                maxsaati = 24;
                maxminuti = 60;
                if(minuta > maxminuti) minuta -= maxminuti, saat++;
                if(saat > maxsaati) saat -= maxsaati, den++;
                if(den > maxdenovi) den -= maxdenovi, mesec++;
                if(mesec > 12) mesec -= 12, godina++;
                TextDrawSetPreviewModel(Slika[playerid], PlayerInfo[playerid][pSlika]);
                Cekazapasos[playerid] = 1;
                SCMF(playerid, COLOR_WHITE, "{C3D900}Ja ostavivte slikata na salter, vasiot pasos e naracan i ke bide gotov na %02d/%02d/%d vo %02d:%02d", den,mesec,godina,saat+1,minuta);
Reply
#18

bump
Reply
#19

This seems to work quite well:
pawn Код:
new godina, mesec, den, maxdenovi, saat, minuta;
    godina = 2014;                
    mesec = 12;                
    den = 31;                
    saat = 26;                
    minuta = 90;                
    switch(mesec)
    {  
        case 1, 3, 5, 7, 8, 10, 12: maxdenovi = 31;
        case 4, 6, 9, 11: maxdenovi = 30;
        case 2: maxdenovi = ((!(godina % 4)) ? (29) : (28));
    }  
    if(minuta >= 60) minuta -= 60, saat++;
    if((saat += 1) >= 24) saat -= 24, den++;
    if(den > maxdenovi) den -= maxdenovi, mesec++
    if(mesec > 12) mesec -= 12, godina++;
    TextDrawSetPreviewModel(Slika[playerid], PlayerInfo[playerid][pSlika]);
    Cekazapasos[playerid] = 1;
    SCMF(playerid, COLOR_WHITE, "{C3D900}Ja ostavivte slikata na salter, vasiot pasos e naracan i ke bide gotov na %02d/%02d/%d vo %02d:%02d", den, mesec, godina, saat, minuta);
Reply
#20

Quote:
Originally Posted by Threshold
Посмотреть сообщение
That was my first thought too, but then I came up with this:
pawn Код:
new year, month, day, maxdays;
    getdate(year, month, day);
    printf("Date: %02d/%02d/%d", day, month, year);
    switch(month)
    {
        case 1, 3, 5, 7, 8, 10, 12: maxdays = 31;
        case 4, 6, 9, 11: maxdays = 30;
        case 2: maxdays = ((!(year % 4)) ? (29) : (28));
    }
    if((day += 5) > maxdays) day -= maxdays, month++;
    if(month > 12) month -= 12, year++;
    printf("Date +5 days: %02d/%02d/%d", day, month, year);
Simply replace 'year', 'month' and 'day' with your own variables.

Код:
case 1, 3, 5, 7, 8, 10, 12: maxdays = 31;
		case 4, 6, 9, 11: maxdays = 30;
		case 2: maxdays = ((!(year % 4)) ? (29) : (28));
This says, if month is 1, 3, 5, 7 etc., the maximum days in that month will be 31. This never changes depending on the year.
If the month is 4, 6, 9, 11, the maximum days in that month will be 30. This never changes depending on the year.
If the month is February, we need to check if it's a leap year to determine whether the maximum days will be 28 or 29.
Код:
maxdays = ((!(year % 4)) ? (29) : (28));
Leap years occur every 4 years, so we can simply just see whether the year is divisible by 4 by doing: '!(year % 4)'. Thus we can determine whether it is a leap year or not. This pretty much translates to:
pawn Код:
if(leapyear) maxdays = 29;
else maxdays = 28;
Код:
if((day += 5) > maxdays) day -= maxdays, month++;
If adding 5 days to the number of days is greater than the maximum days in that month, we need to change the month and reset the days.
Код:
if(month > 12) month -= 12, year++;
If we happen to be in December and moving into the next year, this updates the years and resets the months.
Very nice, I would write it myself for him but I was in a lazy mood
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)