SA-MP Forums Archive
Data passed - 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)
+--- Thread: Data passed (/showthread.php?tid=616783)



Data passed - MerryDeer - 10.09.2016

Hi,

It's possible to check if certain date is passed or no?


Re: Data passed - Kaliber - 10.09.2016

What you mean exactly?


Re: Data passed - KaisAggarwal - 10.09.2016

Explain more with a clear screenshot or more info i dont understand what your trying to say actually btw.


Re: Data passed - MerryDeer - 10.09.2016

Like i have date for ex:

2016/09/11 15:30

Now is:

2016/09/10 17:53

How to check if that first date is passed? like i want to make player can write command Up to a certain date


Re: Data passed - Kaliber - 10.09.2016

Ahh okay, you can do this like this:

PHP код:
new d,m,yh,mi,s;
getdate(y,m,d),gettime(h,mi,s);
if(
>= 2016 && >= && >= 11 && >= 15 && mi >= 30)
{
    
//Here its the 11.09.2016 after 15:30
}
else
{
    
//Here its before




Re: Data passed - MerryDeer - 10.09.2016

What if i have string where is that data?


Re: Data passed - Kaliber - 10.09.2016

You have to split..that string..

Give an Example string you wanna type in


Re: Data passed - ScIrUsna - 10.09.2016

new data[ 50 ];
data = "2016/09/11 15:30";


Re: Data passed - Kaliber - 10.09.2016

Dude...thats...a stupid way to store this...
easy would be sth like.."2016/09/11/15/30";

Then just use the split function...and set this in the if condition..


Re: Data passed - Konstantinos - 10.09.2016

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
easy would be sth like.."2016/09/11/15/30";
I'd rather have a readable form than this. Not that it is hard to split with ScIrUsna's code:
pawn Код:
sscanf(date_time, "p</>iiip<:>iiI(0)", year, month, day, hour, mins, sec);
Anyway, I think what he actually wants to say is if the datetime specified is in the future. If that is:
pawn Код:
mktime(const mdate_mtime[], utcdiff = 0)
{
    new year, month, day, hour, mins, sec, tyears, tdays, leaps, utc_hrs;
    static const mon_days[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304};
   
    sscanf(mdate_mtime, "p</>iiip<:>iiI(0)", year, month, day, hour, mins, sec);

    month--;
    year -= 1900;
   
    tyears = year - 70;
    leaps = (tyears + 2) / 4;
   
    tdays = mon_days[month];
   
    tdays += day - 1;
    tdays = tdays + (tyears * 365) + leaps;

    utc_hrs = hour + utcdiff;
    return (tdays * 86400) + (utc_hrs * 3600) + (mins * 60) + sec;
}
pawn Код:
if (mktime(datetime_specified_by_user, -GMT) > gettime()) return ...
// ... return error that this date has yet to come
In the UTC difference, add the GMT the server is on but negative.