日期型能直接相减
procedure TForm1.Button1Click(Sender: TObject);
var
a1:tdate;
begina1:=date;
showmessage(floattostr(a1-strtodate('2002-2-12')));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a1:tdate;
begina1:=date;
showmessage(floattostr(a1-strtodate('2002-2-12')));
end;
日期型能直接相减吗 能
把data转化为int 强制转换就可以.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.text := DateToStr(date); //* check-in date *//
Edit2.text := Edit1.text; //* check-out date *//
Edit3.Text := '123.00'; //* room rate *//
end;procedure TForm1.Button1Click(Sender: TObject);
beginEdit4.text := FloatToStr(StrToFloat(Edit3.text)*(StrToDate(Edit2.text)-StrToDate(Edit1.text)));
end;end.
===================================================object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 48
Top = 24
Width = 42
Height = 13
Caption = 'Check-in'
end
object Label2: TLabel
Left = 176
Top = 24
Width = 49
Height = 13
Caption = 'Check-out'
end
object Label3: TLabel
Left = 304
Top = 24
Width = 54
Height = 13
Caption = 'Room-Rate'
end
object Button1: TButton
Left = 208
Top = 88
Width = 75
Height = 25
Caption = 'Balance'
TabOrder = 0
OnClick = Button1Click
end
object Edit1: TEdit
Left = 48
Top = 40
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit1'
end
object Edit2: TEdit
Left = 176
Top = 40
Width = 121
Height = 21
TabOrder = 2
Text = 'Edit2'
end
object Edit3: TEdit
Left = 304
Top = 40
Width = 121
Height = 21
TabOrder = 3
Text = 'Edit3'
end
object Edit4: TEdit
Left = 304
Top = 88
Width = 121
Height = 21
TabOrder = 4
Text = 'Edit4'
end
end
好象是miniusbetween() hoursbetween这一类的,到帮助里面去
查查看
procedure TtuifangForm.jiezhangButtonClick(Sender: TObject);
var
riqi:tdate;
begin
riqi:=date;
moneyedit.text:=floattostr(20*(riqi-strtodate(enterdatedbedit.Text)));
end;