Topic: Covert Date to String

Hi in the picture I send you my problem.

I try to Convert the Date to string. I try it using the FormatToDate  or the StrToDate but somewhere I make a mistake. Can someone help me ?
from 2016-3-15  to  15/3/2016.

Post's attachments

Attachment icon date.jpg 5.4 kb, 305 downloads since 2016-05-06 

Re: Covert Date to String

You can do the following:
String_Date := Formatdatetime('DD/MM/YYYY', Date);

3 (edited by v_pozidis 2016-05-06 17:04:34)

Re: Covert Date to String

Clicking on a TableGrid it should show in the EditBox the date.

Here is my script

var
s:string;

begin
  s := SQLExecute('Select ImerominiaFakelou from Ypothesi WHERE id=' + IntToStr(frmEpilogiYpothesis.TableGrid1.dbItemID));
  frmEpilogiYpothesis.Edit2.Text:=s;

end;

the s should have the date

When I give your script it shows the current date and not the date there is in the record.
Where is my mistake?

Thank's in advance

Re: Covert Date to String

Hello,
I think I would do it this way to save making an extra call to the database, but I am sure there will be other ways to do it too.
******************************************************************************
Var YY,MM,DD : integer; mydate: tdatetime;
procedure whatever_you_want
begin
    mydate := form1.DateTimePicker1.datetime;
    DeCodeDate (mydate,YY,MM,DD);
    form1.edit1.text := inttostr(dd) +'/'+ inttostr(mm) +'/' + inttostr(yy);
end;
******************************************************************************
I have attached this in a little project to show it working. 
Maybe it will help,
Derek.

Post's attachments

Attachment icon pozidis.zip 337.66 kb, 415 downloads since 2016-05-07 

Re: Covert Date to String

Thank you for your help but this solution is to complex. I 'm sure there must be another way

Re: Covert Date to String

v_pozidis,
Attached is a possible solution using the method you are trying to do.

Post's attachments

Attachment icon Pozidis_Date_Reformat.zip 337.63 kb, 412 downloads since 2016-05-09 

Re: Covert Date to String

Yes this works. !!!!!!!!!!!!  Thak's  to all of you.