dBase date fields

I have a file with a dBASE date field.
I want to convert the date field
from mm/dd/yy to a string of yyyymmdd

anybody know how?
dateToStr i dont think converts it to yyyymmdd

HELP..thanks
waipahuAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
williams2Connect With a Mentor Commented:
In the win32 page on the delphi-component menu, you'll find a component named TDateTimePicker. It will do exactly as you have planned to do. You can customize it to show either date or time with the .kind property.

You can also make it parse the userinput automatically.

Regards,
Williams
0
 
williams2Commented:
It easily solved.

You can use this function:

function FormatDateTime(const Format: string; DateTime: TDateTime): string;

this example shows how to do this:

The following example assigns 'The meeting is on Wednesday, February 15, 1995 at 10:30 AM' to the string variable S.

S := FormatDateTime('"The meeting is on" dddd, mmmm d, yyyy, ' + '"at" hh:mm AM/PM', StrToDateTime('2/15/95 10:30am'));


You can also lookup FormatDateTime in the index of the Delphi Help, which provides more help.

Regards,
Williams
0
 
waipahuAuthor Commented:
THanks for the help! it works..
i got another question....
is there a function to check if the date field contains valid dates?

something like this
If ValidDate(datefield) then....


0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
williams2Commented:
If my proposal worked why in H.. did you reject it??????????????
0
 
waipahuAuthor Commented:
THanks for the help! it works..
i got another question....
is there a function to check if the date field contains valid dates?

something like this
If ValidDate(datefield) then....


0
 
waipahuAuthor Commented:
It did work, but how do you validate if the date field contains a valid date?
I am doing a conversion program that reads a file that contains a date field
and move that date field into a character field.  I am erroring out on the date field.
Somehow when i call the FormatDateTime function it errors out. I think
before i call the FormatDateTime function i have to validate if the content of
the date field contains a valid date.  What if its blank, or contain other stuff.

Thanks for your help!!!
0
 
waipahuAuthor Commented:
It did work, but how do you validate if the date field contains a valid date?
I am doing a conversion program that reads a file that contains a date field
and move that date field into a character field.  I am erroring out on the date field.
Somehow when i call the FormatDateTime function it errors out. I think
before i call the FormatDateTime function i have to validate if the content of
the date field contains a valid date.  What if its blank, or contain other stuff.

Thanks for your help!!!
0
 
rwilson032697Commented:
Waipahu,

Williams2 answered your question perfectly. Go and give him his points (I think an 'A' is deserved).

At 10 points a pop you can afford to post another question. ;-)

Cheers,

Raymond.

0
 
williams2Commented:
I guess Waipahu is not familiar with the site yet, let's give the guy a fair start :-)

Cheers,
Williams
0
 
waipahuAuthor Commented:
I'm Sorry, I thought if I accepted your answer you wouldn't follow up on my other concern
about validating dates.
SOrry. I really appreciate all your help. Believe it or not without your help, would
have a hard time. I am just learning Delphi and I think it is a very powerful language, problem is I just don't know all the functions and syntax and all the capabilities
of this langauge.  I know where i wanna go, just trying to get there is a bit difficult.

Thanks!

input date field (defined in a dBase file as D)  -------> validating program -----> valid date?

that is all i want to check for. Does the input date field contain a valid date.
The initial question was about formating the date, this other question is how
to validate the date field.

The input date field is coming in from external source......i am validating the data using
my delphi program.

thanks so much!
0
 
waipahuAuthor Commented:
check this program out:
if you put an invalid date in, it will ERROR off...
Put a valid date in and it will be okay.
I want a way to validate the date before calling any date conversion routines.
Thanks

procedure TForm1.Button1Click(Sender: TObject);
var
  indate: TdateTime;
begin
  indate := strtodate('02/31/98');
  showmessage(datetostr(indate));
end;

end.

0
 
waipahuAuthor Commented:
StrToDate( ) function is not Y2k compliant.

if you have a date '02/02/00'   this will be interpreted as 02/02/1900 ..how do i fix this
problem.
using Delphi 3 professional.

thanks!

0
 
williams2Commented:
You should then use exception handling, this is the best way of getting the right result:

Example:

Function TForm1.testDate(DateStr: String): Boolean;
begin
  Try
    strtodate(DateStr);
    Result:= True;
  Except
    on EConvertError do Result:= False;
  End;
End;

procedure TForm1.Button1Click(Sender: TObject);
var
  indate: TdateTime;
  DateStr: String;
begin
  DateStr:= '02/31/98';
  If testDate(DateStr) then
  begin
    indate := strtodate('02/31/98');
    showmessage(datetostr(indate));
  End else
    showmessage('Please write date in the format yy:mm:dd');
end;


The procedures above will raise an exception when working in Delphi, but when you are executing outside Delphi, nobody would know even if an error happened!

Regards,
Williams
0
 
williams2Commented:
..Hmmm I made a little bug, hehe:

indate := strtodate(DateStr);

0
 
williams2Commented:
You may have a look in the Delphi help indexing "date/time formatting variables"

here you can change the way DateToStr and StrToDate behaves. You can then make your app. Y2K compliant

Regards,
Williams
0
 
waipahuAuthor Commented:
check this program out:
if you put an invalid date in, it will ERROR off...
Put a valid date in and it will be okay.
I want a way to validate the date before calling any date conversion routines.
Thanks

procedure TForm1.Button1Click(Sender: TObject);
var
  indate: TdateTime;
begin
  indate := strtodate('02/31/98');
  showmessage(datetostr(indate));
end;

end.

0
 
waipahuAuthor Commented:
I still got an error when i enter the Testdate function.
it will error off on the strtodate(datastr);
doesn't error trap it.
have any clue?
thanks
0
 
williams2Commented:
As I said! The error is still showing when running with Delphi.

The error is gone, when you just startup the .exe file WITHOUT Delphi. Delphi does this to help the developer tracking Exceptions, even though you've allready catched it!

If that doesn't help, then read in the message, what the Exception name is and then replace it in the on ... do block.

You could also just remove the on ... do block, leaving the:
Result:= False;

Then the Try..Except block will trap all error events!

Regards,
Williams
0
 
gallagheCommented:
Consider Checking/setting the "ShortDateFormat" variable in Delphi and the "DateDelimitor" var when working with dates.
Both get info from Windows...
0
 
williams2Commented:
Yes! ..But you could identify where in the variables you'll find a sting 'yy' and replace it with 'yyyy'.

This solves that problem taking care of the date/time settings for the current locale settings.

Regards,
Williams
0
 
rwilson032697Commented:
You should also check out the century window feature of D4, this allows you to specify how two digit dates are interpreted.

Raymond.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.