Check if valid date
#1

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
Reply
#2

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)
Reply
#3

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
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)