Hi,
I am trying to write a program that will show the difference between two days. The end or ( to date) will be given(CONSTANT). But the from date must be entered in the edit box in the following format:
YEAR, MONTH, DATE, HOURS,MIN,SEC. example
2009,01,22,12,32,02

I will be happy to get assistance.

Below is an example for EncodeDate() and EncodeTime() functions:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  YY:     Word;
  MM:     Word;
  DD:     Word;
  HH:     Word;
  MN:     Word;
  SS:     Word;
  E:      Integer;
  I:      Integer;
  J:      Integer;
  L:      Integer;
  N:      Integer;
  DT:     TDateTime;
  TM:     TDateTime;
  C:      string;
  S:      string;
  T:      string;
begin
  J := 1;
  N := 0;
  C := ',';
  S := Edit1.Text;
  L := Length(S);
  for I:=1 to L do
  begin
    if (S[I]=C) then
    begin
      T := Copy(S,J,I-J);
      J := I + 1;
      Inc(N);
      case N of
        1: Val(T, YY, E);
        2: Val(T, MM, E);
        3: Val(T, DD, E);
        4: Val(T, HH, E);
        5: Val(T, MN, E);
      end;
    end;
  end;
  T := Copy(S,J+1,L);
  Val(T, SS, E);
  DT := EncodeDate(YY,MM,DD);
  TM := EncodeTime(HH,MN,SS,0);
  Edit2.Text := FloatToStr(DT);
  Edit3.Text := FloatToStr(TM);
end;

end.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.