Solved

Delphi 4 : Incrementing the result of 'Now' by a negative amount of minutes

Posted on 2006-11-30
8
681 Views
Last Modified: 2011-09-20
Hello.

I have the below line:

 if (StrToDateTime(QueryNextRun.FieldByName('report_lastrun').AsString) > IncMinute(Now, -180)) then

Which fails to work, as I am using Delphi 4, and I guess IncMinute is in the later versions.

So my question is, how can I achieve the above in Delphi 4?

Just want to compare 2 date/time values, where the 1st comes from a SQL table (Format: dd/mm/yyyy HH:MM:SS) and the second is Now minus about 180 minutes
0
Comment
Question by:wbstech
[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
8 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 500 total points
ID: 18044590
use now - 180/1440

meikl ;-)
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 18044624
When calculating with date/time, you have the following rule :
1 exact day = 1 (So Now + 1 = tomorrow).

So :
1 day = 1
--> 1 minute = ( 1 / 24 ) / 60 = 6,9444444444444444444444444444444e-4
--> 180 minutes = 6,9444444444444444444444444444444e-4 * 180 = 0,125


In a Delphi Example :

var
  aDate: TDateTime;

  aDate := Now;
  showmessage( FormatDateTime( 'dd/mm/yyyy hh:nn:ss:zzz', aDate ) +
               #13#10 +
               FormatDateTime( 'dd/mm/yyyy hh:nn:ss:zzz', aDate-StrToFloat(Edit5.Text) ) );


This shows you exactly the current date/time and current date/time minus 180 minutes.

So, instead of IncMinute(Now, -180) you can use (Now-0.125)

Best regards,

The Mayor.
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 18044639
damn, too slow again ! ;-)
0
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!

 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 18044649
Btw, I found IncMinute in the DateUtil-Unit of the RxLib !

Didn't know about that function.

So, if you have RxLib installed, it is enough to include the DateUtil in your uses-clause.
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 18044687
In this unit DateUtil.pas there is :

function IncMinute(ATime: TDateTime; Delta: Integer): TDateTime;
begin
  Result := IncTime(ATime, 0, Delta, 0, 0);
end;


and of course also :

function IncTime(ATime: TDateTime; Hours, Minutes, Seconds,
  MSecs: Integer): TDateTime;
begin
  Result := ATime + (Hours div 24) + (((Hours mod 24) * 3600000 +
    Minutes * 60000 + Seconds * 1000 + MSecs) / MSecsPerDay);
  if Result < 0 then Result := Result + 1;
end;

the variable MSecsPerDay = 24 * 60 * 60 * 1000
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 18044761
Or you can make you own IncMinute-Function Like this :

function IncMinute( ATime: TDateTime; Delta: Integer ): TDateTime;
begin
  Result := aDate + ( ( ( 1 / 24 ) / 60) * Delta );
end;
0
 
LVL 45

Expert Comment

by:aikimark
ID: 18044851
reference for future readers:
NOW (Windows timestamp) is a floating point numeric value with the integer value being the number of days since 1899-12-31 (yyyy-mm-dd format) and the decimal value being a percentage of the date (starting at midnight).

There fractional part of the day is usually displayed down to a one second granularity, but it is accurate down to 1/100 second.

To avoid unnecessary divisions, remember these conversion constants:
86400 - seconds in a day
1440 - minutes in a day
24 - hours in a day (duh)

==================================
If you need a more granular or more reliable timestamp, you would avoid NOW and use a Multi-Media timing value or a Tick timing value.
0
 
LVL 4

Author Comment

by:wbstech
ID: 18053589
Thanks for the massive amount of detail folks. Didn't expect all that! :-)
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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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