DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

IsValidDate

Checks if a string represents a valid date in the current locale.

function IsValidDate(const DateString: string): Boolean;
var
  DT: TDateTime; // unused date time value
begin
  Result := SysUtils.TryStrToDate(DateString, DT);
end;

IsValidTime

Checks if a string represents a valid time in the current locale.

function IsValidTime(const TimeString: string): Boolean;
var
  DT: TDateTime; // unused date time value
begin
  Result := SysUtils.TryStrToTime(TimeString, DT);
end;

SecondsToTime

Converts a number of seconds into a TDateTime value.

function SecondsToTime(const ASeconds: Cardinal): TDateTime;
const
  MSecsPerSec = 1000;  // ms per day: not defined in Delphi 6 and earlier
begin
  Result := ASeconds / SysUtils.MSecsPerDay * MSecsPerSec;
end;

View the whole database.

Go to the DelphiDabbler website.