validating date field

HELP ME

i like to validat date field...

for that i declare it as character and validating it
i found this type of error.


for '12/712/00' input it working

DEFINE VARIABLE d AS DATE FORMAT "99/99/9999" NO-UNDO.

ASSIGN d = DATE('12/712/00') no-error .
IF ERROR-STATUS:ERROR THEN
DO:
IF( INDEX(ERROR-STATUS:GET-MESSAGE(1),'day' ,1))<> 0 THEN
disp " NVD-DAY".
ELSE
IF ( INDEX(ERROR-STATUS:GET-MESSAGE(1),'month' ,1))<> 0 THEN
disp " NVD-month" .
ELSE disp " NVD-YEAR".
END.
IF d = ? THEN
disp " NVD".
disp d.

/***********/

FOR 12/5P/JJ INPUT IT NOT VALIDATING

IT DISPLAY DATE AS 12/05/200 HOW CAN I OVERCOME THIS PROBLEM?
 
Hi,

I think it is not considering the characters. We can use some alternate method for validating the date other than this, like using the entry function for each token.

Prasad
 
You can use the validating you are currently using but one way to get around checking there is no characters inside your character string would be to check the date result after is the same as what you had input at the start.

DEFINE VARIABLE d AS DATE FORMAT "99/99/9999" NO-UNDO.
DEFINE VARIABLE inputdate AS CHARACTER NO-UNDO.
inputdate = "12/12/JJ".

ASSIGN d = DATE(inputdate) no-error .
IF inputdate <> STRING(d) THEN
DISP "error".
ELSE
DISP "OK".
 
Hi,

What you have mentioned is correct, but still for the above example what you have given (12/12/JJ) it will display date with current year (12/12/2007) without any error. In order to search whether character is present or not in string one should break the string into tokens and check the same.

Thanks
 
Hi,

What you have mentioned is correct, but still for the above example what you have given (12/12/JJ) it will display date with current year (12/12/2007) without any error. In order to search whether character is present or not in string one should break the string into tokens and check the same.

Thanks

Why not disallows the entering of letters into the character field, so the user can only enter numbers. You can easily do this by adding a ANY-PRINTABLE or ANY-KEY trigger in your code. See my previous sample. When you do this then there is no need to add this into a validation routine. In a good UI you should give the user only the option to enter the things that are allowed, nothing is more annoying then post validition error messages.
 
Back
Top