DateUtils.DateTimeToString

Delphi 12 update 1 DateTimeToStr is in the
C:\Program Files (x86)\Embarcadero\Studio\23.0\source\rtl\sys\System.SysUtils.pas

function DateTimeToStr(const DateTime: TDateTime): string; overload; inline;
function DateTimeToStr(const DateTime: TDateTime;
  const AFormatSettings: TFormatSettings): string; overload; inline;

But the word “interface” is not in this System.SysUtils file where it should be
meaning the entire file is not accessible to the complier
At the same time their is many double standards to the one instruction that is totally frustrating.
This word inline; - what does it mean to the complier? overload?

Can I just get a file with the complete function please -
function DateTimeToStr(const DateTime: TDateTime;
const AFormatSettings: TFormatSettings): string;

“inline” means: embed the code in the compiled output, rather than calling it as a function.

Hi, Lex.

Line 27 of the file is “interface”

Inline : https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Calling_Procedures_and_Functions_(Delphi)

Overload : Tells the compiler that there are multiple definitions of the method. Allows the method to be executed with multiple different parameter sets, so for the example, the function could be executed with parameter of TDateTime alone or (TDateTime and TFormatSettings).

Personally, I believe that overload is redundant, since It is sufficient for all methods with the same name to have different signatures (ordered set of parameter-types&return-type.) RSP-13778 issue closed on Nov 22, 2019 by Marco Cantù with comment:
This is a key language features (that has been copied by other programming languages), not going to change it

…PW

1 Like

the real issue i cannot use this function
the ide puts a read line under it but i cannot get the real error

Never mind the red lines.

What is the actual error message from the compiler???

Their is no overload version of DateTimeToStr that can be called with these arguments
The IDE shows these values between the brackets

System.SysUtils.DateTimeToStr(aRecord.DateTime,  'dd MMM,yyyy');

I cannot be more instructive with my code to Delphi
aRecord.DateTime is my TDateTime value

The message is quite clear - you’ve made a mistake and the compiler is letting you know.

If you look at the page explaining the DateTimeToStr function you can see there is not a version which takes a string as the second argument: System.SysUtils.DateTimeToStr - RAD Studio API Documentation.

There is a function where you can do that: System.SysUtils.FormatDateTime - RAD Studio API Documentation

NOTE again that the format string in the first instance is the FIRST parameter.

You would use it like this: System.SysUtils.FormatDateTime( 'dd MMM,yyyy', aRecord.DateTime);

The function you are calling - and the second version of FormatDateTime expects a parameter of TFormatSettings.

An example of how to use TFormatSettings can be found here: TFormatSettings (Delphi) - RAD Studio Code Examples

It’s a record - you should pre-populate it first to get the operating system defaults and then override them if you need to - BUT I suggest you use the FormatDateTime function instead based on what you’re trying to do.

1 Like

I get it - I don’t understand why not uniform everything
rename FormatDateTime to DateTimeToStr
and remove FormatDateTime as a Delphi instruction so you have 1 rock sold instruction for the task!!!
To be RAD its about having a RAD layout to the Instruction set
At the same time their is so much good about Delphi as a language
may be I’m a perfectionist sorry

I have a TDateTimePicker on my form and when I set the TDateTimePicker and trace DTPicker.DateTime is my input not my output of what I just manually as a user set it at, why? where is the output from what the user set it at?
Date and time are original settings

procedure TForm1.DTPickerExit(Sender: TObject);
begin
  If LBRec.LBData = lbDate then LBRec.Date := DTPicker.Date;
  If LBRec.LBData = lbTime then LBRec.Time := DTPicker.Time;
  If LBRec.LBData = lbDateTime then LBRec.DateTime := DTPicker.DateTime;
end;

Please start a new topic when appropriate

Have you tried the OnChange event?

I think its the complier needing a rebuild and its made the connection?