Solved

Add 5 minutes

Posted on 2001-09-13
6
371 Views
Last Modified: 2010-04-06
Simple question:

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

Thanks
0
Comment
Question by:olisaac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6480523
datetime := datetime + 1/(24*20);
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6480528
sorry

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

Expert Comment

by:kretzschmar
ID: 6480586
another method, better readable

const
  MinutesPerDay = 1440;

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

meikl ;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
Jacco earned 30 total points
ID: 6480698
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);

function DateTimeAdd(aDateTime: TDateTime; aTimePart: TTimePart; aQuantity: Integer): TDateTime;
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);
  aTime := TimeStampAdd(aTime, tpMinute, 5);
  Memo1.Lines.Add(DateTimeToStr(TimeStampToDateTime(aTime)));
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  aTime: TDateTime;
begin
  aTime := Now;
  aTime := DateTimeAdd(aTime, tpMinute, 5);
  Memo1.Lines.Add(DateTimeToStr(aTime));
end;
0
 
LVL 1

Author Comment

by:olisaac
ID: 6481153
kretzschmar, your answers don't give me the right value

It's ok Jacco

Thank you Jacco and kretzschmar for your quick answers
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6481572
as you mean,
(of course my first comment was wrong (typo))

meikl ;-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Connection between libmysql.dll and MySQL Versions 7 132
Firemonkey webbrowser scrollbars ? 1 69
Firemonkey BASS_Init into a thread 17 82
TlistView is Really heavy on Android 3 43
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question