Solved

Retro Y2K failure.

Posted on 2002-06-05
7
245 Views
Last Modified: 2010-04-04
Using a Paradox table in a Delphi program which in part calculates age, dates prior to 1/1/2000 are read as 2001 year.  So someone born in 1995 has an age of -93 years!  The Paradox table is set to fourdigityear = true, yet it is obviously not working as one.  Any answers to how to get it to work right?  Is there a Delphi solution or this a Paradox problem? Is there a Delphi fix to a Paradox problem.
0
Comment
Question by:dpnd88
7 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 7056959
sounds like an y2k-problem,
is your shortdate-setting of your system to four digits?
can you show your calculation routine?
0
 
LVL 4

Expert Comment

by:Greg Rowland
ID: 7057187
Is the data bad when read in?

I have been very successful using FormatDateTime() to force dates to behave.

Examples;


wwTable1.FieldByName('DATE_RECEIVED').Text := FormatDateTime('mm/dd/yyyy', StrToDate(MaskEdit1.Text));

wwTable2.FieldByName('DATE_SENT').Text := FormatDateTime('mm/dd/yyyy', wwDBDateTimePicker1.Date);

myArray[1, 1] := FormatDateTime(' mmmm d, YYYY', Date);

0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 7058854
Maybe it is not the Paradox-Table,
but only you way of calcuating the Age that results in strange values.

Can you post your code to do the calculations ?

Best regards,

The Mayor.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

Author Comment

by:dpnd88
ID: 7059336
The calculations work on dates after 1/1/2000.  That the same mechanism results in the calculations using a 2000 date for a 1900 date tells me it something in the unpublished coding.
Surfer Joe may have the answer by suggesting to format the date before it saved to table.  Let's clarify some things.  I am using two calendars to calculate age by taking the computer numeric date and converting to a string date and then performing math and converting back to a date. Does dateTimePicker offer some internal function for calculating an interval?  Here is the coding I used for calculating the date (which, again, works on post Y2K dates) and saving to table.
dob = date of birth
bd = birthday
td = today's date
dob:= (dbedit8.text);
MonthCalendar4.Date:= StrToDate(dob);
td:= (MonthCalendar3.Date);
bd:= (MonthCalendar4.Date);
Months:= ((td-bd)/30.5);
Edit66.text:= FloatToStrF(Months, ffFixed, 3,1);
years:= (Months/12);
Edit60.text:= FloatToStrF(Years, ffFixed, 3,1);
Age:= Years;
Edit58.text:= FloatToStrF(Age, ffFixed, 3,1);
Edit4.Text:= DateToStr(MonthCalendar3.Date);

Label3.Caption := Format('Current Age: %3.2f years ',[Years]);

then to post the data:
Table11.FieldByName('Date').AsFloat:= strToDate(Edit4.Text);
Table11.FieldByName('months').AsFloat:= strToFloat(Edit66.Text);
Table11.FieldByName('years').AsFloat:= strToFloat(Edit60.Text);
Table11.Post;

So according to Surfer Joe I need to format the first line of data going into the table, the
Table11.FieldByName('Date').AsFloat:= strToDate(Edit4.Text); line, even though the table is supposed to be formated already?  Your code is different than what I am using, the ".Text" vs. the "AsFloat".
I think you have the right answer but I don't understand your context as well as my own. Give a bit of advice on this and you win, Surfer Joe.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7059372
>Your code is different than what I am using, the ".Text"
>vs. the "AsFloat".

seems to be a typo,

i prefer and recommend for datevalues the AsDateTime-method
rather than AsFloat because the internal Datevalue of
the database may other than the TDateTimeType vs. FloatType

maybe this causes your problem.

btw.
why do you convert the date into a string?
or other why do you use a string-conversion for your calculation if you have the date already?
(you may crash by other regional settings)

meikl ;-)
0
 

Author Comment

by:dpnd88
ID: 7063252
Yes, the system shortdate setting was not set properly!  I thought I had that checked but apparently not.  Thank you.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7063398
glad to helped you :-)

well, if this was the cause,
you do not need to change the systemsettings
(the format is only taken from there during app-init)

just add this lines at appstart
(im formcreate-event of the mainform for example)

shortdateformat := 'mm/dd/yyyy';  
dateseparator := '/';

this will change the shortdateinterpetation
for your app only, so it doesn't effect the system
and the app works with this format

meikl ;-)
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question