DateUtils.DateTimeToString

DateTimeToString no longer exists?

              DateUtils.DateTimeToString(DataName, 'dd/mmm/yyyy', MyDate);
              Grid.Cells[2, Grid.RowCount -1] := DataName;

Their must be something to cover dates and times to a string?
Is any one familiar with this subject please

Depending on your format requirements, you can try DateTimeToStr

I like FormatDateTime. Functions are better. :slight_smile:

   Grid.Cells[2, Grid.RowCount -1] := FormatDateTime('dd/mm/yyyy', MyDate);  
// m    = 8
// mm   = 08
// mmm  = Aug
// mmmm = August

https://docwiki.embarcadero.com/Libraries/Athens/en/System.SysUtils.FormatDateTime

hay guys thanks to know your way around
This page has to go or needs a rethink to remove this fustration
https://docwiki.embarcadero.com/Libraries/Athens/en/System.SysUtils.FormatDateTime
It needs pulling down ASAP

If Delphi developers makes a date time utility file its got to be orderly
that means all date time utilities must be in the file regardless of everything else so it can be found.
and this applies to every type of utility - floating point - currency
and this System.******** has to stop it needs total subject focus for once
or finding things is no longer RAD

Its not your fault its Delphi developers that needs to get a strict order process in place

and function FormatDateTime(const Format: string;
DateTime: TDateTime): string; overload; inline;
with procedure DateTimeToString(var Result: string; const Format: string;
DateTime: TDateTime); overload; inline;
the first one is the wrong words and needs to Go Go Go to remove all confusion as it does the same job but with the wrong words. the 2nd one needs to be a function and with the same name!!!
Then it aligns up with IntToStr and all the other utilities in an order to follow
what ever the order developed its got to be through out
If the name is correct - that is the most important thing!!!
if you change it from procedure to function big deal its able to be found and the IDE will point out the error and change that is an easy fix.
example Utilities.DateTime Utilities.Float Utilities.Currency Utilities.IntWords … then the file its self becomes a bit of a help file in its self
Delphi 12 is big and has a lot to it that it needs a fundamental order to get around it is what I’m saying.
I found ‘CopyMemory’ - what a good Utility - Good sold naming too - better than move’

Another thing you do a search for a Delphi *.pas file and you sometimes get 3 different copies -
a) C:\Program Files (x86)\Embarcadero\Studio\23.0\lib\win32\release
b) C:\Program Files (x86)\Embarcadero\Studio\23.0\lib\win32\debug
c) C:\Program Files (x86)\Embarcadero\Studio\23.0\source\rtl\sys
d) C:\Program Files (x86)\Embarcadero\Studio\23.0\lib\win64\release
e) C:\Program Files (x86)\Embarcadero\Studio\23.0\lib\win64x\release
f) C:\Program Files (x86)\Embarcadero\Studio\23.0\lib\win64\debug
g) C:\Program Files (x86)\Embarcadero\Studio\23.0\lib\win64x\debug
I’m running 64 bit Delphi so that rules the first 3 out, but which x64 one is being complied?

Any way I’m heavy into a project and this forum is very supporting and I like the members hear - they are very helpful in deed and these little things can slow me down greatly where you guys makes the difference.
I’m now heavy into the front end and what to be finished before Christmas.
thanks again

System.SysUtils.DateTimeToString
System.SysUtils.DateTimeToStr

With the format string the ‘System.SysUtils’ file shows them but the IDE will not compile them as they all do a red line under them in the IDE. Why?

Do you have system.sysutils in either of your uses sections?

Yes I have standard Delphi 12 installed with only a few IDE preference adjustments
this is a Delphi fix

1 Like

Roger means do you have code like this:

uses system.sysutils;

The way you are typing out System.SysUtils.something is the full reference to the function and the namespace. If you hover over the red lines it should tell you what is wrong.

If you add the above ‘uses’ line to your program it should fix those problems unless you’ve got something else wrong in your code like a syntax error or missing string terminator - the message on the red lines should give you a hint as to what is wrong.

I always copy and paste
System.SysUtils
to make secure its letter prefect
I put the full stop in and get the menu and add the .DateTimeToStr
to get System.SysUtils.DateTimeToStr
and that is where the error is as the complier will not accept it
yet it came out of the menu

I’m not sure you understand the purpose of uses statements or how name spaces work.

If you add System.SysUtils to your uses clauses you don’t need to respecify it again - just use DateTimeToStr on its own.

Writing it out in full like that is unnecessary and for many developers would be considered irritating - some software teams would explicitly ask you not to do that too since brevity and succinctness in code is considered an asset which is kind of why the concept of namespaces exists in most high-level programming languages.

The error you have is not anything to do with that. Perhaps if you take a screenshot of the error message or write down what it says someone here can suggest what is wrong and how to fix it.

2 Likes

Ian, I agree with you, but with with one caveat. There are some instances where you have to specify the unit name to inform the compiler which unit you want to use as the definition. This happens when the same item is defined in more than one unit.

Now, you might say that you put the unit that has the definition you want earlier or later in the USES list. This can get messed up if you sort your uses list alphabetically (I do). Now the wrong definition is used by the compiler and compiler-error chaos ensues.

Using the unitname.definitionname syntax insures that the correct one will be used. TBitmap defined in both WinApi.Windows and Vcl.Graphics: I am looking at you.

Yes, doing this unnecessarily drives me absolutely nuts too… as does “Self.MethodName”, but that is a whole other rant.

lol

My personal favorite is TRect which has driven me to distraction several times, particularly when 3rd party libraries suddenly decide it’s absolutely fine to create their own version.

I feel your pain! :joy:

1 Like

How about TPath? :roll_eyes:

1 Like

uses system.sysutils; has to be installed in the correct place that when I type in the implementation area system.sysutils. the menu can only pop up if system.sysutils is linked to a file to reference from and so I select from the IDE menu the methods in the file but the methods do not settle to compile
is the system.sysutils.DCU file missing?

What exactly does not compile?

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.Menus, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.Grids;

…
…

procedure TForm1.GridSetEditText();
Var
Val: string;
begin
Val := System.SysUtils.DateTimeToStr(MyDateTime,‘dd,mmm,yyyy’);
It goes on about an overload value not being set that is a complier error in Delphi code?

Hi, use FormatDateTime for this.

FormatDateTime(‘dd,mmm,yyyy’, MyDateTime);

(Also in System.SysUtils)

DateTimeToStr takes an optional format settings value which is not a string.
It is generally used to print out date/times in various standard windows formats depending on your Region, usually not for fully custom formats.

Note: You can put your cursor somewhere in the method name press F1 in Delphi, and mine at least finds some reasonable information on it for most of the Delphi supplied methods.
Also on my help page under see also for these methods, is a reference to Date and Time Support.

after a little bit of time working on it
System.SysUtils.DateTimeToStr(MyDateTime,‘dd,mmm,yyyy’);
the format string causes an error

@lexdeanair
When you use the code completion suggestion, you’ll see the arguments listed for the two overloads …

function DateTimeToStr(const DateTime: TDateTime): string;

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

If you use Ctrl-Click on “DateTimeToStr” to take you to the source … and again to look up “TFormatSettings”

You’ll see TFormatSettings is a pretty big Record … not a String.

It isn’t used the way you are trying to use it : System.SysUtils.TFormatSettings - RAD Studio API Documentation

You can still use this approach … but the namespace is ‘System.SysUtils’.

              System.SysUtils.DateTimeToString(DataName, 'dd/mmm/yyyy', MyDate);
              Grid.Cells[2, Grid.RowCount -1] := DataName;