Solved

Add 5 minutes

Posted on 2001-09-13
6
372 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

617 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