Simple question:

how can I add 5 minutes to a TdateTime variable
and same question for a timestamp variable

Thanks
LVL 1
###### Who is Participating?

Commented:
Hi there,

The TTimeStamp question is a little different.

Here is some code I cooked up:

Regards Jacco

const
HoursPerDay           =   24;
MinutesPerHour        =   60;
SecondsPerMinute      =   60;
MilliSecondsPerSecond = 1000;

MilliSecondsPerDay    = HoursPerDay * MinutesPerHour * SecondsPerMinute * MilliSecondsPerSecond; // also defined in SysUtils
MilliSecondsPerHour   = MinutesPerHour * SecondsPerMinute * MilliSecondsPerSecond;
MilliSecondsPerMinute = SecondsPerMinute * MilliSecondsPerSecond;

DayValue          = 1;
HourValue         = DayValue    / HoursPerDay;
MinuteValue       = HourValue   / MinutesPerHour;
SecondValue       = MinuteValue / SecondsPerMinute;
MilliSecondValue  = SecondValue / MilliSecondsPerSecond;

type
TTimePart = (tpHour, tpMinute, tpSecond, tpMilliSecond);

begin
case aTimePart of
tpHour       : Result := aDateTime + aQuantity * HourValue;
tpMinute     : Result := aDateTime + aQuantity * MinuteValue;
tpSecond     : Result := aDateTime + aQuantity * SecondValue;
tpMilliSecond: Result := aDateTime + aQuantity * MilliSecondValue;
end;
end;

function TimeStampAdd(aTimeStamp: TTimeStamp; aTimePart: TTimePart; aQuantity: Integer): TTimeStamp;
begin
Result.Date := aTimeStamp.Date;
case aTimePart of
tpHour       : Result.Time := aTimeStamp.Time + aQuantity * MilliSecondsPerHour;
tpMinute     : Result.Time := aTimeStamp.Time + aQuantity * MilliSecondsPerMinute;
tpSecond     : Result.Time := aTimeStamp.Time + aQuantity * MilliSecondsPerSecond;
tpMilliSecond: Result.Time := aTimeStamp.Time + aQuantity;
end;
Result.Date := Result.Date + aTimeStamp.Time div MilliSecondsPerDay;
Result.Time := Result.Time mod MilliSecondsPerDay;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
aTime: TTimeStamp;
begin
aTime := DateTimeToTimeStamp(Now);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
aTime: TDateTime;
begin
aTime := Now;
end;
0

Commented:
datetime := datetime + 1/(24*20);
0

Commented:
sorry

datetime := datetime + 1/(24*12);
0

Commented:

const
MinutesPerDay = 1440;

DateTime := DateTime + 1/(MinutesPerDay*5);

meikl ;-)
0

Author Commented:

It's ok Jacco

0

Commented:
as you mean,
(of course my first comment was wrong (typo))

meikl ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.