Board index » delphi » DBase date fields fields -> Y2K?

DBase date fields fields -> Y2K?

Hi

(Delphi 1, DBase engine)
In my data base, I allow users to enter dates - how can I force them to
enter long dates (e.g. 1999, 2000, instead of 99, 00)?  And what about
checking if today's date is between 1999 and 2010?  Or should I change
all my date fields to Strings, and perform all the Y2K checks manually?

--
Ken Masters
University of Cape Town
Cape Town, South Africa
Computer-Based Education? See http://www.uct.ac.za/projects/cbe/
----------------------------------------------------------------

 

Re:DBase date fields fields -> Y2K?


There are a couple of ways to accomplish this, such as setting
ShortDateFormat to a four-year date, using edit masks, etc.

I wouldn't change my dates to strings, but I would consider converting
them to float fields and storing TDateTime types.  Just be careful
that you don't mix 16 and 32-bit Delphi apps with that solution
because the numbers TDateTime represents is different between Delphi 1
and the rest.

-Peter

On Fri, 23 Oct 1998 11:31:04 +0200, Ken Masters <k...@its.uct.ac.za>
wrote:

Quote
>Hi

>(Delphi 1, DBase engine)
>In my data base, I allow users to enter dates - how can I force them to
>enter long dates (e.g. 1999, 2000, instead of 99, 00)?  And what about
>checking if today's date is between 1999 and 2010?  Or should I change
>all my date fields to Strings, and perform all the Y2K checks manually?

Re:DBase date fields fields -> Y2K?


Quote
Ken Masters (k...@its.uct.ac.za) wrote:

: In my data base, I allow users to enter dates - how can I force them to
: enter long dates (e.g. 1999, 2000, instead of 99, 00)?  And what about
: checking if today's date is between 1999 and 2010?  Or should I change
: all my date fields to Strings, and perform all the Y2K checks manually?

As someone else suggested, either change the Windows default
short date on all machines, or (preferably) use an edit mask.
But don't panic thinking that you'll have a Y2K problem just
because the date if formatted for a 2-digit year; as long as
you're using date fields, it will be stored as a true date,
including the century.  And no, I wouldn't convert to strings.
--
============================================================
Rick Carter   carte...@email.uc.edu   rcar...@tso.cin.ix.net
============================================================

Re:DBase date fields fields -> Y2K?


Quote
Richard wrote in message <70rbh1$lv...@news.ececs.uc.edu>...

when replying to

Quote
>Kens (k...@its.uct.ac.za) question....

>As someone else suggested, either change the Windows default
>short date on all machines, or (preferably) use an edit mask.
>But don't panic thinking that you'll have a Y2K problem just
>because the date if formatted for a 2-digit year; as long as
>you're using date fields, it will be stored as a true date,
>including the century.  And no, I wouldn't convert to strings.

All of the date fields in my tables are of type - "Date",
I have set the date configuration in the BDE Administrator to dd/mm/yyyy.
I use both TDatePickers and dbEdits for date entry, the user can either type
or select a date.

Set my machines date format to dd/mm/yy and run the app.
Enter a date by TYPING it in (say...12/12/00), which my database stores as a
*Date*,
Reset the machine date format to YYYY

....fall over as you see the date appears as 1900.

I may be wrong here, (As I start to correct this problem in my app, but I
will be decoding all dates and if an entry is made with ONLY two digits for
the year, I will be converting it to a date between 1975 and 2075 or
whatever the standard is.

To that end...how do you find out what the users machine's date format is?
It could be messy converting a date that you *assume* is dd/MM/yy when it is
actually MM/dd/yy. On the 12/12/98, you would be hard pressed to know the
difference.

Am I on the right track here?

heidi

--
many thanks

heidi

Please remove STOPSPAM from my email address

---------------------------------------------------------------------
   Choose Cruelty Free - not tested on animals
http://www.onthenet.com.au/~tropix/Welcome.html
         Free guide to cruelty free shopping
---------------------------------------------------------------------

Re:DBase date fields fields -> Y2K?


Quote
"heidi" <tropixSTOPS...@onthenet.com.au> wrote:
>Richard wrote in message <70rbh1$lv...@news.ececs.uc.edu>...
>when replying to
>>Kens (k...@its.uct.ac.za) question....

>>As someone else suggested, either change the Windows default
>>short date on all machines, or (preferably) use an edit mask.
>>But don't panic thinking that you'll have a Y2K problem just
>>because the date if formatted for a 2-digit year; as long as
>>you're using date fields, it will be stored as a true date,
>>including the century.  And no, I wouldn't convert to strings.

>All of the date fields in my tables are of type - "Date",
>I have set the date configuration in the BDE Administrator to dd/mm/yyyy.
>I use both TDatePickers and dbEdits for date entry, the user can either type
>or select a date.

>Set my machines date format to dd/mm/yy and run the app.
>Enter a date by TYPING it in (say...12/12/00), which my database stores as a
>*Date*,
>Reset the machine date format to YYYY

>....fall over as you see the date appears as 1900.

>I may be wrong here, (As I start to correct this problem in my app, but I
>will be decoding all dates and if an entry is made with ONLY two digits for
>the year, I will be converting it to a date between 1975 and 2075 or
>whatever the standard is.

>To that end...how do you find out what the users machine's date format is?
>It could be messy converting a date that you *assume* is dd/MM/yy when it is
>actually MM/dd/yy. On the 12/12/98, you would be hard pressed to know the
>difference.

>Am I on the right track here?

>heidi

>many thanks

Heidi,

        Regarding your first example, by setting the BDE to a 4 digit
year is right.  However, you need to remember that the database engine
(according to the documentation) will assume current century if it is
not entered, hence the 00 -> 1900 when using the short date format.
You can programmatically change the short date format without changing
every machine the software is installed on.  If you use the date
formatting routines included in Delphi, the date format is changed
only for the application, and the rest of the time it is whatever the
user selected.

        In regards to you second situation (dd/MM/yyyy vs. MM/dd/yyyy)
what I did for my apps is have the hints turned on and the date format
displayed (Show Hints = TRUE).

Mike

------------------------------------------------------
- Mike Bandor  (band...@vitrex.net)
- Software Engineer:    Delphi/Ada/C++/Java/Win3.1/
-                       Win95/Winhelp/JOVIAL/MASM
-                              
- "Trying to manage programmers    
-  is like trying to herd cats!"          
-
- Speaking for myself!  Standard disclaimer applies.
------------------------------------------------------
- Author of MEGATERMS:  Military Terms and Acronyms
- http://www.vitrex.net/~bandorm/megaterm/megaterm.htm
- ftp://vitrex.net/usr/b/bandorm/m-term.zip
------------------------------------------------------

Re:DBase date fields fields -> Y2K?


I still haven't seen a definitive answer for this one so I will push
on...and hey...I chew some serious painkillers..so I am allowed to be a bit
hazy!!!

Question One----

How do you format a date...then store it in a dbTable as DateTime (ie: a
float), then redisplay it already formatted, independent the operating
system formats? ....

Have I asked that the wrong way around. Do you store the date as
DateTime...then re-format every date record....*every time*.... the data is
displayed??

OR...do you just store all of your dates as strings? (as previously
suggested by someone)

Question Two----

My understanding of Delphi BDE and Y2k is that Delphi will assume that a two
digit date is within the date range of the current century. That being the
case, is it correct to say you must declare to your users that all dates
entered outside of the current century using the dd/mm/yy format will be
wrong unless you decode and convert the date entries?

many thanks

heidi

Please remove STOPSPAM from my email address

---------------------------------------------------------------------
   Choose Cruelty Free - not tested on animals
http://www.onthenet.com.au/~tropix/Welcome.html
         Free guide to cruelty free shopping
---------------------------------------------------------------------

Re:DBase date fields fields -> Y2K?


Quote
>How do you format a date...then store it in a dbTable as DateTime (ie: a
>float), then redisplay it already formatted, independent the operating
>system formats? ....

>Have I asked that the wrong way around. Do you store the date as
>DateTime...then re-format every date record....*every time*.... the data is
>displayed??

Yes, the other way around.  But remember that the Date and Time
properties of a TDateTimePicker are both of type TDateTime, so they
can be set directly to the floating point TDateTime type stored in the
database.

Quote
>Question Two----

>My understanding of Delphi BDE and Y2k is that Delphi will assume that a two
>digit date is within the date range of the current century. That being the
>case, is it correct to say you must declare to your users that all dates
>entered outside of the current century using the dd/mm/yy format will be
>wrong unless you decode and convert the date entries?

I'll have to look back through your messages in case you answered
this, but why not simply require a 4-digit entry?

Good luck,
-Peter

Re:DBase date fields fields -> Y2K?


At startup simply parse the ShortDateFormat (it is the copy of system
setting) variable and if if has a two digit year, change it to 4 digit year,
so when the user enters a two digit year into dbedit, it will be reformatted
to four digit. In D1 the date conversion routine allways assumes 19'th
century, so the user will immediately see that it's not correct. You can go
to SYSUTILS unit and change this (as I did), but be VERY carefull, you may
modify implementation part, but do never change the interface part.
D4 solved this problem with pivot.
--
-------------------------
Regards,
Robert

Remove leading aa when replying.
MailTo: aarobert.ce...@eunet.si

Quote
heidi wrote in message <710gat$s4...@corolla.OntheNet.com.au>...
>I still haven't seen a definitive answer for this one so I will push
>on...and hey...I chew some serious painkillers..so I am allowed to be a bit
>hazy!!!

>Question One----

>How do you format a date...then store it in a dbTable as DateTime (ie: a
>float), then redisplay it already formatted, independent the operating
>system formats? ....

>Have I asked that the wrong way around. Do you store the date as
>DateTime...then re-format every date record....*every time*.... the data is
>displayed??

>OR...do you just store all of your dates as strings? (as previously
>suggested by someone)

>Question Two----

>My understanding of Delphi BDE and Y2k is that Delphi will assume that a
two
>digit date is within the date range of the current century. That being the
>case, is it correct to say you must declare to your users that all dates
>entered outside of the current century using the dd/mm/yy format will be
>wrong unless you decode and convert the date entries?

>many thanks

>heidi

>Please remove STOPSPAM from my email address

>---------------------------------------------------------------------
>   Choose Cruelty Free - not tested on animals
>http://www.onthenet.com.au/~tropix/Welcome.html
>         Free guide to cruelty free shopping
>---------------------------------------------------------------------

Re:DBase date fields fields -> Y2K?


Quote
heidi wrote in message <710gat$s4...@corolla.OntheNet.com.au>...
>My understanding of Delphi BDE and Y2k is that Delphi will assume
that a two
>digit date is within the date range of the current century. That
being the
>case, is it correct to say you must declare to your users that all
dates
>entered outside of the current century using the dd/mm/yy format will
be
>wrong unless you decode and convert the date entries?

Your assumption is correct. The simplest solution, as you suggest, is
to insist on users entering 4 digit years. (And set ShortDateFormat to
'dd/mm/yyyy' so dates are always displayed in full.)

Some commercial apps like Excel assume that dates from 1/1/00 to
1/1/30 are meant to be in the next century, while anything later is in
the current century. You could try using the TField's OnValidate event
to test the TDateTime value of the entered date and add 100 years if
the year is between 1900 and 1930.

--
Stephen Brown

Other Threads