比如一个文本框里是一个2012-3-4这样子的格式加上一个数字,比如5年、 6年、10年什么的,能得到的是一个字符串还是一个日期:
字符串转换为日期型怎么转,我用了STRTODATE(EDIT.TEXT)老是出错,不知道怎么引用,procedure TForm1.Button1Click(Sender: TObject);
var
year,month,day:word;now2 : TDateTime;
begin
now2:=date();
decodedate(now2,year,month,day);
label1.Caption := inttostr(year)+'年'+inttostr(month)+'月'+inttostr(day)+'日';//这里都可以正常运行edit1.text:=StrTodate(label1.caption);//这里出错
end;
错误提示:
[Error] Unit1.pas(38): Incompatible types: 'String' and 'TDateTime'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
问题1label1.Caption是一个字符串吗?
如何将edit1.text:=的内容转成一个日期型数据呢
字符串转换为日期型怎么转,我用了STRTODATE(EDIT.TEXT)老是出错,不知道怎么引用,procedure TForm1.Button1Click(Sender: TObject);
var
year,month,day:word;now2 : TDateTime;
begin
now2:=date();
decodedate(now2,year,month,day);
label1.Caption := inttostr(year)+'年'+inttostr(month)+'月'+inttostr(day)+'日';//这里都可以正常运行edit1.text:=StrTodate(label1.caption);//这里出错
end;
错误提示:
[Error] Unit1.pas(38): Incompatible types: 'String' and 'TDateTime'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
问题1label1.Caption是一个字符串吗?
如何将edit1.text:=的内容转成一个日期型数据呢
或
edit1.text:=DateToStr(Date);
程序里好像直接用STRTODATE 就会出错
+5.5就是+5年再+上半年的意思吧implementation
uses DateUtils;
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var temp:TDateTime;
begin
temp := IncYear(StrToDateTime('2012-3-4'),5);
ShowMessage(DateToStr(IncMonth(temp,6)));
end;