# Thread: Increase hour in TDateTime

1. ## Increase hour in TDateTime

Hi,

It's been several months but I'm back into scripting/botting. Almost finished my Grand Exchange Flipping script and now I'm making a Farming script; it will do tree runs. I'm saving the time and date in a file so the script can restart where it's left. Now I'm trying to figure out how to deal with calculating with TDateTime.

First I decode the date and time.

Code:
DecodeDate(Now(), _year, _month, _day);
DecodeTime(Now(), _h, _m, _s, _ms);
Now I'm trying to figure out how to add like 4 hours and make a new TDateTime. Al my ways leads to not changing the date (day, month, year). I'm looking for a function like Delphi has: 'IncDay()' and 'IncHour()'. Is there a way to get this done?

I've made a hackish kind of way, but that leads to not changing the date.
Code:
timeInMS := (Integer(_h) * 3600000) + (Integer(_m) * 60000) + (Integer(_s) * 1000) + Integer(_ms);
timeInMs := timeInMs + TreeType.Duration;
if (timeInMs > 86400000) then
begin
timeInMs := timeInMs - 86400000;
inc(_day);
end;

2. So, just like this for all the simple normal cases:
Simba Code:
var  d:TDateTime := Now();begin  WriteLn(d);  WriteLn(TDateTime(d+2.3{inc by 2.3 hours}/24{hours per day}));end.

3. Originally Posted by slacky
So, just like this for all the simple normal cases:
Simba Code:
var  d:TDateTime := Now();begin  WriteLn(d);  WriteLn(TDateTime(d+2.3{inc by 2.3 hours}/24{hours per day}));end.
Exactly what i needed! Thanks!