On 1997-11-13 (16:45) RON TUYNMAN wrote
RT> As an absolute beginner I'm not able to calculate the number of days
RT> between today and a given date in a database (dBase III+ table).
RT> After weeks of experimenting I'm able to calculate the number of
RT> days between two dates with TRUNC ( date1 - date2 ), but when I
RT> replace one of those variables with the datefield from the table,
RT> things go wrong.
RT> In my former language I just simply used the very simple frase:
RT> Days := date1 - date2
RT> I'm using Delphi 1.0
Here's an example showing date manipulation. If your dBASE date is in
a string form, then it has to be converted to a Delphi date form. Then
it's a simple matter to subtract one date from the other.
program CrtApp;
{ Language...: Delphi 1.0 }
{ Written for public consumption }
{ No copyrights by me }
{ Tested on 11/18/97 by SM Read }
uses WinCrt, SysUtils;
var
StrDate1, StrDate2 : String[10];
ADate1, ADate2 : TDateTime;
begin
Writeln('Today''s date is ', FormatDateTime('mm/dd/yy',Now));
Writeln('The date in two weeks will be ',
FormatDateTime('mm/dd/yy',Now + 14));
Writeln('The date two weeks ago was ',
FormatDateTime('mm/dd/yy', Date - 14));
Writeln( 'The date string is ', DateToStr(date));
Writeln( FormatDateTime( +
'"Sortable date format... " yyyymmdd"', date ) );
StrDate1 := '09/07/1997';
StrDate2 := '09/28/1997';
ADate1:= StrToDate(StrDate1);
ADate2 := StrToDate(StrDate2);
Writeln( 'Subtracting dates... ',+
StrDate2, ' - ', StrDate1, ' = ', +
(ADate2-ADate1):1:0 );
Writeln( 'Subtracting dates... ',+
'Today - ', StrDate1, ' = ', +
(Now-ADate1):1:0 );
end.
RT> Thanx by Tom (son), Anita (wife) and Kikomas (dog)...
Glad to help. ;-)
Steve
--- InterEcho 1.19
---------------
* Origin: PC-Ohio PCBoard * Cleveland, OH * 216-381-3320 (1:157/200)
|