SA-MP Forums Archive
Check if valid date - 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: Check if valid date (/showthread.php?tid=608617)



Check if valid date - Jonesy96 - 03.06.2016

Hi,

I'm retreving a date via dialog input. How can I check and ensure that the date is valid in the format DD/MM/YYYY. Is it possible?

Thanks


Re: Check if valid date - PrO.GameR - 03.06.2016

sscanf could help, with '/' delimiter and 3 integers you could extract them, then check the day month and year for appropriate ranges (1-31 days, 1-12 months, +1900 year sth)


Re: Check if valid date - Jonesy96 - 03.06.2016

Hi, I figured as much actually,t hank you. Could you give me some advice on how I would split the string with sscanf? I'm new to sscanf so am unsure.

Thanks


Re: Check if valid date - Konstantinos - 03.06.2016

The delimiters can be done with "p" or "P" (for optional) specifiers. Optional specifier is needed sometimes to avoid some sscanf warnings when characters such as parenthesis are used.

pawn Код:
// assuming "text" stores "03/06/2016"
new
    dd,
    mm,
    yy;

sscanf(text, "p</>iii", dd, mm, yy);
// dd = 3
// mm = 6
// yy = 2016