Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Delphi equivalent for TDateTime.FormatString


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Nov 6, 2017 4:23 PM Last Post By: Remy Lebeau (Te...
Robert [NL] Mit...

Posts: 100
Registered: 5/23/04
Delphi equivalent for TDateTime.FormatString  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 7:56 AM
C++ has System.TDateTime.FormatString(const System::String& format), to format a string to a TDateTime variable based on a arbitrary format, like yyyymmddhhmmss
But this method is somehow not implemented for Delphi. What is the Delphi pascal equivalent for this?

Note I want to convert a string with an arbitrary format into TDateTime, not to other way around.

(Using Delphi 10.1 Berlin)
John David

Posts: 86
Registered: 9/5/16
Re: Delphi equivalent for TDateTime.FormatString  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 12:34 PM   in response to: Robert [NL] Mit... in response to: Robert [NL] Mit...
On 05/11/2017 15:56, Robert [NL] Mittendorff wrote:
C++ has System.TDateTime.FormatString(const System::String& format), to format a string to a TDateTime variable based on a arbitrary format, like yyyymmddhhmmss
But this method is somehow not implemented for Delphi. What is the Delphi pascal equivalent for this?

Note I want to convert a string with an arbitrary format into TDateTime, not to other way around.

(Using Delphi 10.1 Berlin)

Try this:

<http://www.delphibasics.co.uk/RTL.asp?Name=formatdatetime>
Robert [NL] Mit...

Posts: 100
Registered: 5/23/04
Re: Delphi equivalent for TDateTime.FormatString  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 12:57 PM   in response to: John David in response to: John David
Looks the other way round, i.e. datetime to string, not string to datetime.
Nigel Thomas

Posts: 15
Registered: 4/26/07
Re: Delphi equivalent for TDateTime.FormatString  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 4:14 PM   in response to: Robert [NL] Mit... in response to: Robert [NL] Mit...
Robert [NL] Mittendorff wrote:

Looks the other way round, i.e. datetime to string, not string to
datetime.

Is VarToDateTime whay you might be looking for?

Nigel
Uffe Kousgaard

Posts: 218
Registered: 2/7/00
Re: Delphi equivalent for TDateTime.FormatString  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 6, 2017 8:16 AM   in response to: Robert [NL] Mit... in response to: Robert [NL] Mit...
Robert [NL] Mittendorff wrote:

C++ has System.TDateTime.FormatString(const System::String& format),
to format a string to a TDateTime variable based on a arbitrary
format, like yyyymmddhhmmss But this method is somehow not
implemented for Delphi. What is the Delphi pascal equivalent for this?

Note I want to convert a string with an arbitrary format into
TDateTime, not to other way around.

(Using Delphi 10.1 Berlin)

function strtodate ( const Date : string; const FormatSettings :
FormatSettings ) : TDateTime;
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Delphi equivalent for TDateTime.FormatString
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 6, 2017 4:23 PM   in response to: Robert [NL] Mit... in response to: Robert [NL] Mit...
Robert [NL] Mittendorff wrote:

C++ has System.TDateTime.FormatString(const System::String& format),
to format a string to a TDateTime variable based on a arbitrary
format, like yyyymmddhhmmss But this method is somehow not
implemented for Delphi. What is the Delphi pascal equivalent for this?

If you look at the source code for TDateTime::FormatString() (in $(BDS)\
source\vcl\datetime.cpp), you would see that it is just a thin wrapper
for Sysutils::FormatDateTime():

System::String __fastcall TDateTime::FormatString(const System::String&
format) const
{
  return Sysutils::FormatDateTime(format, *this);
}


Which in turn is just a thin wrapper for Sysutils::DateTimeToString()
(in $(BDS)\source\rtl\sys\System.SysUtils.pas):

function FormatDateTime(const Format: string; DateTime: TDateTime):
string;
begin
  Result := FormatDateTime(Format, DateTime, FormatSettings);
end;
 
function FormatDateTime(const Format: string; DateTime: TDateTime;
  const AFormatSettings: TFormatSettings): string;
begin
  DateTimeToString(Result, Format, DateTime, AFormatSettings);
end;


Note I want to convert a string with an arbitrary format into
TDateTime, not to other way around.

Use Sysutils::StrToDateTime() (which can be called directly, or via the
TDateTime constructor in C++).

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02