Solved

Add 5 minutes

Posted on 2001-09-13
6
366 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
  • 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now