Sign in Join
FPDoc Onlineexperiment

IsValidDateTime function

In unit DateUtils

Check whether a set of values is a valid date and time indication.

Declaration

pascal
function IsValidDateTime(const AYear: Word; const AMonth: Word; 
 const ADay: Word; const AHour: Word; 
 const AMinute: Word; const ASecond: Word; 
 const AMilliSecond: Word): Boolean

Arguments

AYear

Year value.

AMonth

Month in the year.

ADay

Day in the month.

AHour

Hour of the day.

AMinute

Minute in the hour.

ASecond

Second in the minute.

AMilliSecond

Milliseconds in the second.

Function result

True if the given values form a valid date/time pair, False if not.

Description

IsValidTime returns True when the values AYear, AMonth, ADay, AHour, AMinute, ASecond and AMilliSecond form a valid date and time indication. If one of the values is not valid (e.g. the seconds are larger than 60), False is returned.

AYear must be in the range 1..9999 to be valid.

See also

Example: ex7

pascal
Program Example7;

{ This program demonstrates the IsValidDateTime function }

Uses SysUtils,DateUtils;

Var
  Y,Mo,D : Word;
  H,M,S,MS : Word;
  I : Integer;

Begin
  For I:=1 to 10 do
    begin
    Y:=2000+Random(5);
    Mo:=Random(15);
    D:=Random(40);
    H:=Random(32);
    M:=Random(90);
    S:=Random(90);
    MS:=Random(1500);
    If Not IsValidDateTime(Y,Mo,D,H,M,S,MS) then
      Writeln(Y,'-',Mo,'-',D,' ',H,':',M,':',S,'.',MS,' is not a valid date/time.');
    end;
End.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.