CPB Mailing List
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: TDateTime
On Wed, 7 Oct 1998, Thomas Browns wrote:
> A quick question: I have been using the 'StrToDate()' function to
> access user input from an edit box
> When I enter a date like '06/10/03' using the European convention
> 'dd/mm/yy' and use the 'DecodeDate()' function to peek into the
> TDateTime variable dt, I find the year '1903'!?
> I can't believe BCB has a year 2000 problem so any tips on getting out
> the right date?
It seems to me that it is your program that is not Y2K compliant rather
than being a problem with BCB. If you allow a user to enter a 2-digit
year value, your program will be non-compliant unless you perform
some some sort of windowing (or other procedure of your choice) to
assign the desired century value. This is true no matter what development
tool you use. What if you happen to be writing a program to catalog
paintings from the 17th - 19th centuries? Even if Borland did implement
some sort of auto-windowing it couldn't possibly anticipate every
program's specific needs. Since there is no way for Borland to know what
century your date field is supposed to represent, they apparently
default to 1900 if you don't supply a century. The responsibility for
assigning the correct century rests on your shoulders if this default
behavior doesn't satisfy your program requirments.
The fact that BCB3 automatically assigns a century value of 19 means that
it is Y2K compliant in the respect that a BCB TDateTime object will always
have a valid date including century even if you don't supply it with a
compliant date for construction. It is up to you to make sure that date
object reflects the information you wish to store/present.
A few suggestions that might help you solve your problem...
1. Don't let the users enter a non-compliant 2-digit year. Use a mask to
require a Y2K compliant ccyy format for the year.
2. If you allow users enter a 2-digit year, don't convert the text
directly into a date object. Instead, run all your date text
strings through a validation function (that you would write).
This function would look at the date string and if the year was a
compliant 4-digit value then it would return the string with no
modification. If the year was a non-compliant 2-digit value then
it would insert a century value based on some cutoff year of your
choice (this is called windowing). The output string from this
validation function would then be converted to a date object.
3. Don't use an editbox for the date entry, use TDateTimePicker instead.
Since this is a wrapper for a win32 common control, it would then be
up to MS to maintain compliance on the part of their OS.
Hope this gives you a few ideas, let me know if you have any questions ;)
Daniel Hallmark
- References:
- TDateTime
- From: Thomas.Browns@kpmg.co.uk (Thomas Browns)
W Komornicki's Home Page |
Main Index |
Thread Index