Valid DATE function

Valid DATE function

Postby Rick Lipkin » Wed May 23, 2007 4:59 pm

To All

Does anyone have a function that will test for valid dates .. .DBF is rather forgiving when you write back a date like "01/01/0200" .. but ADO will give you a run-time error on a date like I just mentioned.

Does anyone have a routine or function that will test for a valid date for a date field 'mm/dd/yyyy ??

Thanks
Rick Lipkin
SC Dept of Health
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby James Bott » Wed May 23, 2007 6:49 pm

Rick,

Hmm, isn't 01/01/0200 a valid date?

Don't you just want to test for some defined date range? Perhaps something like:

function checkDate( dDate )
return if(year (dDate) > 1980, .t., .f. )

If hard-coding the minimum date is an issue, then you could just keep track of the oldest date ever entered, and then question the user when they enter one older than that.

"Did you really mean the year 200?"

This way then can still enter a date outside the known range, if indeed it is what they wanted.

If your users are entering dates, and if you provide them with a popup calendar and/or default dates, then you are much less likely to get typos.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Gale FORd » Wed May 23, 2007 9:43 pm

How about

function checkDate( dDate )
return if(year (dDate) > date()-200 .or. empty( dDate ), .t., .f. )
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Rick Lipkin » Wed May 23, 2007 11:30 pm

James and Gale


> Hmm, isn't 01/01/0200 a valid date?

YES it is ... but not in the realm of ( xHarbour ) ADO ( above date gives a run-time when you write to a table with ADO ) .. and on the way home from work this evening I kinda thought about a (year ) comparison between date() and varDate.. much like you both suggest and throw up an alert for +- maybe 20 years or so ....

Have to consider this a bit more ..

Thank you both.

Rick
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby James Bott » Thu May 24, 2007 1:24 am

Rick,

Another thing I use is background color. You could color the background of the GET yellow when the date is questionable. I have one like this that turns yellow when questionable and even puts up a tooltip with a message. The tooltip then vanishes as any tooltip does. This way the user doesn't have to stop everything to deal with it (no buttons to push). In this instance it is not critical that it be fixed.

The tooltip also appears when the data is questionable, and the cursor hovers over the field.

You may have to force the user to fix the date or at least leave it blank. I suggest not forcing the user to enter a date, since the user will often just fudge and enter any valid date so they can close the dialog. This is worse than no date since it appears to be correct. At least an empty date is easy to find. I would color the GET background pink if no date is entered and the field is critical.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 57 guests