我的数据表T1内有字段chno char(12)
内有数据
chno datetime
031108 2003-11-08
031101 2003-11-01
031110 2003-11-00
031111 2003-11-11
031111 2003-11-11
我要一次性把它转成日期型的,格式:2003-11-08 请各位帮忙分别用DELPHI和SQL的代码写出。
内有数据
chno datetime
031108 2003-11-08
031101 2003-11-01
031110 2003-11-00
031111 2003-11-11
031111 2003-11-11
我要一次性把它转成日期型的,格式:2003-11-08 请各位帮忙分别用DELPHI和SQL的代码写出。
窗体上放两edit,一个buttonprocedure TForm1.Button1Click(Sender: TObject);
begin
edit2.Text:=copy(edit1.Text, 1,2)+'-'+copy(edit1.Text, 3,2)+'-'+copy(edit1.Text, 5,2);
end;
begin
close;
sql.clear;
sql.text := 'select chno datetime from T1 ';
open;
fieldbyname('datetime').asdatetime; //输出时间类型的值;
fieldbyname('datetime').asstring; //输出字符'2003-11-8'
end;
不是一个一个记录的转换。
datetime是不是字段?最好不要用这种做为字段。or update 表名 set [datetime]=CDate("2003-11-08") //Access里面可以
我是要把表T1内的所有记录用一个BUTTON ,一次性转为DATETIME型,
不是一个一个记录的转换。循环语句不知如何写?
若要在Delphi中实现格式变换,用FormatDateTime方法
若要在数据库中实现,用convert(SQL Server中的,其他的我不知道)
delphi strtodate