how can i validate a date field

I have fields that are a char type, but contents a date in format like 08/11/2010. how can i validate the entry for a valid date?
thanks
luciliacoelhoAsked:
Who is Participating?
 
CaptainCyrilConnect With a Mentor Founder, Software Engineer, Data ScientistCommented:
IF CTOD(cDate) = {}
    WAIT WINDOW "Date is invalid"
ELSE
    WAIT WINDOW "Date is valid"
ENDIF
0
 
mikegagnonCommented:
set the format of the textbox to D?
0
 
GreatSolutionsC.I.OCommented:
if those fields are textboxes, why not setting their values to {} if it's for data entry?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
IQuittnerCommented:
I agree with Mike that is the easiest solution.  You cannot depend on taking CTOD of a variable because when you check it with the TYPE command it returns date to any value that isn't a date i.e., 01/32/2010... so if you cannot use Mike's suggestion you will not only have to convert it to a date but also check the values in each field MM/DD/YYYY to ensure they are valid for your application.  I have never used CaptainCyril's suggestion and I tested it with an invalid date and it too said it was a date field.
0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
My suggestion is a validation. It takes the value of a string date and it will it say if it's valid or not and it also depends on your SET DATE.


? isValidDate(table.field)

.T. means it is valid
.F. means it is not

FUNCTION isValidDate
LPARAMETERS cDate
RETURN CTOD(cDate) <> {}
0
 
luciliacoelhoAuthor Commented:

CaptainCyril's suggestion solvs the problem.
Ii try to put property format D, mikegagnon suggestion and  the field accept data like: 33/02/2010. how can i do this property format results?
0
All Courses

From novice to tech pro — start learning today.