How to use FormatDateTime to return the default date combined with the current year?

I am using Delphi 2007.

I need to write a FormatDateTime function that always returns 01/01 / in the TDateEdit field (DevExpress component) as EditValue.

I already tried ...

tcxDateEdit1.EditValue := FormatDateTime('01/01/'+ 'yyyy',now); 

and

 tcxDateEdit1.EditValue := FormatDateTime('01/01/yyyy',Now); 

but none of them worked. This leads to an error converting the variant of the string type to double. "Failed to convert variant of type (String) to type (Double)"

+4
source share
1 answer

I only guess, but your EditValue property EditValue similar to the TDateTime (or TDate ) type (while FormatDateTime returns a string ). If this is true, you can try the following:

 tcxDateEdit1.EditValue := EncodeDate(YearOf(Now), 1, 1); 

See also: YearOf , EncodeDate , FormatDateTime documentation

+5
source

Source: https://habr.com/ru/post/1380023/


All Articles