Topic: Display a date into a lebel

Hello

In a project i would like display a date (dd/mm/yyyy) into a label.caption
I retrieve this date by a SQ :

d := SQLExecute('SELECT Date_Saisie FROM CDThek WHERE id = ' + IntToStr(Form1.TableGrid1.dbItemID));

d is declared as a string variable.

What would be the good syntax to display this date into the label (i.e : 09/05/2016) this to avoir error message : Incompatible types: 'string' and 'extended' ?

Thanks in advance

JB

Re: Display a date into a lebel

Maybe the possible solution I presented to V Pozidis in the next topic could help you. Just change the edit.text to label.caption.

Re: Display a date into a lebel

Hello ehwagner

Thanks for your answer
When I used it, I get an error message : incompatible types.

So I use another way :

Form1.Label27.Caption := SqlExecute('SELECT Date_Saisie FROM CDThek WHERE id = ' + IntToStr(Form1.TableGrid1.dbItemID));

It works but the format doesn't suit to me : 2016/05/09 00:00:00
I have to find a way to format it as 06/05/2016

Thanks a lot to you

JB

Re: Display a date into a lebel

Not sure why you get an error. I don't.  If you are able to assign the SqlExecute value to a caption, you should be able to assign it to a string variable. Then breakdown the string variable with the copy function and concatenate the pieces in the order you want for the label.

Re: Display a date into a lebel

Morning JB,
I think I'd do it the same way as EHWagner is suggesting.  Not sure why you're getting any errors.  I probably wouldn't even use a variable (lazy!) - just put it straight into the label.caption and then reformat it directly.
The code I'd use would be:
procedure Form1_TableGrid1_OnClick (Sender: string);
begin
  form1.label1.caption := sqlexecute('select birthday from dates where id =' +inttostr(form1.tablegrid1.dbitemid));
  form1.label1.caption := copy(form1.label1.caption,9,2) +'/'+ copy(form1.label1.caption,6,2) +'/'+ copy(form1.label1.caption,1,4);
end;
Regards,
Derek.

Re: Display a date into a lebel

The easiest way to do that. Simply and quick.
Thank's Derek.

Re: Display a date into a lebel

Hello Derek and Ehwagner and Pozidis

Pozidis' way i the one.
My error message rose because I'd forget a parenthesis.
I fiexd it and now all is OK

Thanks for your help.

JJ