Good day sir! This is AJ again.
Using VFP 9.0, in my form, I have duration textboxes.
The first textbox is for "Duration From:", and the second one is for "Duration To:". The dates From and To should range by a year, for example: 10/30/2012 - 10/30/2013; 09/01/2012 - 09/01/2013.
If a user entered for example: 10/30/2012 - 11/30/2012, I want to display messagebox for invalid dates.
How will I validate the dates? Can you give some simple codes for this. Thank you!
Hi AJ, welcome back...
The easiest way to insure the date range is always exactly one year is to
have the From date entered, then calculate the To date in your form. The
user should not have to enter two dates, if the computer can calculate one
In the valid method of your From date:
ToDate = gomonth(FromDate,12)
1. The above is based on your two textboxes having the variables "FromDate"
and "ToDate" as their ControlSource
2. In this case, the GOMONTH function creates a date 12 months from the FromDate
3. You should also make your FromDate ENABLED = .F. to show the calculated date, but
not allow the user to change it.
NOTE: If you actually want it to be a year, it should be GOMONTH(FromDate,12) - 1
The -1 subtracts a single day. For example, this would give you a range of
1/1/2011 - 12/31/2011 instead of 1/1/2011 - 1/1/2012.
If you really want your user to enter both dates, use the Valid method of the ToDate
to confirm that the ToDate is equal to GOMONTH(FromDate,12)-1 - if it is NOT equal,
return .f. or 0...
if ToDate <> GOMONTH(FromDate,12)-1