FileDate to String

how to convert FileDate to String ?
LVL 2
omsecAsked:
Who is Participating?
 
ZifNabConnect With a Mentor Commented:
Hi omsec,

you can do the following :

convert it to TDateTime and then convert it to string :

e.g.

function FileDateToDateTime(FileDate: Integer): TDateTime;
procedure DateTimeToString(var NewString: string; const Format: string; DateTime: TDateTime);

Or

FileDate is integer, so just convert integer to string :

function IntToStr(Value: Integer): string;

But I guess the first proposal is more appropriate.

Regards, ZiF.
0
 
omsecAuthor Commented:
i know the first function, but what's FileDate : Integer ? Where does it come from, shouldn't there be a function that expects a File - Var ?
0
 
ZifNabCommented:
Ah,

I thought you already had the date of a file because your talking about FileDate.

You can get the FileDate with FileGetDate or through the Time field of the TSearchRec.

e.g.

procedure TForm1.Button1Click(Sender: TObject);
var SearchRec : TSearchRec;
    Date_of_File : TDateTime;
    stDate_of_file : shortstring;
begin
if OpenDialog1.Execute then begin
  FindFirst(Opendialog1.FileName, faAnyFile, SearchRec);
  Date_of_file := FileDateToDateTime(searchRec.Time);
  stDate_of_file := DateToStr(Date_of_file);
  showmessage(stDate_of_file);
 end;
end;

You can make it shorter offcourse.

Zif.
0
 
omsecAuthor Commented:
i don't have a TSearch-Object, it's a simple File Handle (untyped FILE) So how to get the time from this ?
0
 
ZifNabCommented:
then you need to use FileDate := GetFileDate({handle})
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.