Combine Date and Time…

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36411
    JohnG
    Participant

    Hello,

    I want to have a Date edit and a Time edit provide a combined TDateTime value.

    Using 2 TDateTimePickers will give me the desired result in VCL. How do I do this with the Alpha controls? There is the sDateEdit, and sTimePicker, but I don't see a way to make them work together. (See attached test project.)

    Thanks,

    John

    #52990
    CheshireCat
    Participant

    Hello John,

    the following code should work for you:

    Code:
    uses
    DateUtils;

    var
    MyAlphaDateTime : TDateTime;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    //initialize…

    sDateEdit1.Date := Now;
    sTimePicker1.Time := Time;

    MyAlphaDateTime := sDateEdit1.Date + sTimePicker1.Time;
    Label2.Caption := DateTimeToStr(MyAlphaDateTime);

    end;

    procedure TForm1.sDateEdit1Change(Sender: TObject);
    begin
    MyAlphaDateTime := sDateEdit1.Date + sTimePicker1.Time;
    Label2.Caption := DateTimeToStr(MyAlphaDateTime);
    end;

    procedure TForm1.sTimePicker1Change(Sender: TObject);
    begin
    MyAlphaDateTime := sDateEdit1.Date + sTimePicker1.Time;
    Label2.Caption := DateTimeToStr(MyAlphaDateTime);
    end;

    #52996
    JohnG
    Participant
    Quote:

    the following code should work for you:

    So that's how you do it. Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.