var t: TDateTime; begin t := StrToDate('2003-05-31'); t := t - 50; end;
取得当前日期: var temp:Tdatetime;temp:=NOW; 得到前50天 temp:=NOW-50;‘2003-01-08’怎样——————>'2003-1-8' var s:string; begin s:=FormatDateTime('yyyy-m-d',now); showmessage(s); end;
给你个简单的函数: unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } function getAfterDate:TDate; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}function TForm1.getAfterDate: TDate; /// 实现函数 begin Result := now() - 50; end;procedure TForm1.Button1Click(Sender: TObject); begin showmessage(DateToStr(getAfterDate)); ///调用函数 end;end.
t: TDateTime;
begin
t := StrToDate('2003-05-31');
t := t - 50;
end;
var temp:Tdatetime;temp:=NOW;
得到前50天
temp:=NOW-50;‘2003-01-08’怎样——————>'2003-1-8'
var s:string;
begin
s:=FormatDateTime('yyyy-m-d',now);
showmessage(s);
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function getAfterDate:TDate;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.getAfterDate: TDate; /// 实现函数
begin
Result := now() - 50;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(DateToStr(getAfterDate)); ///调用函数
end;end.
showmessage(datetostr((strtodate(formatdatetime('yyyy-mm-dd',date))-50)));
2003-01-08’——————>'2003-1-8'写一句
strtodate(formatdatetime('yyyy-m-d',strtodate('2003-01-08'))
就可以了
d:TDateTime;
begin
d:=Date-50; //Date系统自带函数
Edit1.Text:=DateToStr(d);
end;最简短的程序,结贴吧!
哈哈
d,d1:TDateTime;begin
d:=formatDatetime('YYYY-MM-DD',now);
d1:=d-50;
Edit1.Text:=DateToStr(d);
end;
d:TDatetime;
begin
d:=now()-50;
end;