How inc ddd hh:mm:ss into my datetime?

Hello guys

I have a maskedit where I inform ddd hh:mm:ss and I want to inc my date, I tried this code and it works fine for days but not
for hours :(

For example:  001  02:35:40 add to my date 07/11/2017 13:00:00

procedure TFDatasPrevisao.MaskEdit1Exit(Sender: TObject);
var
  dias, horas, minutos, segundos : String;
  Dt   : TDateTime;
begin
  Dt       := MaskEdit1.DateTime;
  Dias     := Copy(MaskEdit3.text, 1,3);
  Horas    := Copy(MaskEdit3.text, 5, 2);
  Minutos  := Copy(MaskEdit3.text, 8, 2);
  segundos := Copy(MaskEdit3.text, 11, 2);

  if StrToInt( dias ) > 0 then
  Begin
    dt := IncDay(dt, StrToInt( dias ))
  End;

  if StrToInt( horas ) > 0 then begin
     dt := IncHour(dt, StrToInt( horas ))
  end;

  if StrToInt( minutos ) > 0 then begin
     dt := IncMinute(dt, StrToInt( minutos ));
  end;

  MaskEdit2.Date :=  dt;

end;

Open in new window


Whats is wrong? any clue for a better way?

thanks
Alexandre
LVL 1
hidrauAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
Split the data into the day and the time values.  Once you convert the time string into a real time value, you should be able to add it to the real time value (13:00:00) of your date.  If the resulting time is less than the 13:00:00 value, then add 1 to the date increment value.  Next, increment the date value by the adjusted, if necessary, number of days
1
Sinisa VukSoftware architectCommented:
Do you have correct value in dt after line: Dt := MaskEdit1.DateTime ?
Check it first:
Dt       := MaskEdit1.DateTime;
ShowMessage(DateTimeToStr(dt));
...

Open in new window


I would convert all inc values to seconds first - then do Inc afterwards.
...
var
...
  ss: Integer;
begin
...
  Dias     := Copy(MaskEdit3.text, 1,3);
  Horas    := Copy(MaskEdit3.text, 5, 2);
  Minutos  := Copy(MaskEdit3.text, 8, 2);
  segundos := Copy(MaskEdit3.text, 11, 2);

  ss := 0;
  ss := ss + StrToIntDef(Dias,0) * 60 * 60 * 24; //add days
  ss := ss + StrToIntDef(Horas,0) * 60 * 60; //add hours
  ss := ss + StrToIntDef(Minutos,0) * 60; //add minutes
  ss := ss + StrToIntDef(segundos,0); //add seconds

  dt := IncSecond(dt, ss);
...

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hidrauAuthor Commented:
Thanks a lot for the example and explanation
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.