Calculate days between two 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: Calculate days between two dates (
/showthread.php?tid=175383)
Calculate days between two dates -
DeathOnaStick - 09.09.2010
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.
Re: Calculate days between two dates -
Kyosaur - 09.09.2010
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).
Re: Calculate days between two dates -
DeathOnaStick - 10.09.2010
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.