access数据库,其中有几个表,需要对表1进行操作
表1 中有些字段
要对表1中的某个字段进行操作,操作字段为日期型
要求是
用当前日期去减字段中的日期,比如说当前时间比字段时间晚一天,那么就在表1中的内容字段中写入所减出来的值。
请大家帮我
表1 中有些字段
要对表1中的某个字段进行操作,操作字段为日期型
要求是
用当前日期去减字段中的日期,比如说当前时间比字段时间晚一天,那么就在表1中的内容字段中写入所减出来的值。
请大家帮我
begin
edit;
fieldbyname('updatefield').asinteger := date-fieldbyname('olddate').asdatetime;
end;
function IncDay(const AValue: TDateTime;
const ANumberOfDays: Integer = 1): TDateTime
1、注意date类型还是datetime类型,否则出现小数。
2、date1-date2=相差天数,应该是,但我碰到过相差天数要除以2的情况(好象是sql server的 datetime类型)试试看。
表1
|
\ 以前日期 | 内容 | *** | ***
2002-12-6
2002-12-3
2002-5-16
2003-1-23
以上是数据库结构
数据库行数不确定
我要用一个timer对其进行30分钟一次的检查,如果发现有比当前日期小的那就把他的差值写到"内容“这个字段中去
比如2003-1-24 - 2003-1-23=1 然后写到内容上的就是”1“了!
我是初学者,希望大家能说得明白一点!
谢谢
with adotable1 do
begin
edit;
fieldbyname('updatefield').asinteger := date-fieldbyname('olddate').asdatetime;
end;
如果fieldbyname('olddate')大于或等于当前日期,那怎么办?
大家帮帮忙!procedure TForm1.Timer3Timer(Sender: TObject);
begin
while not adotable1.eof do
with adotable1 do
begin
edit;
fieldbyname('内容).asinteger := date-fieldbyname('以前日期').asdatetime;end;
adotable1.Next;end;
begin
adotable1.first;//加这句,而且要保证30分钟内能执行完代码。
while not adotable1.eof do
with adotable1 do
begin
edit;
fieldbyname('内容').asinteger := now-fieldbyname('以前日期').asdatetime;//在内容右边少了但引号???
//如果结果为小数或等于实际值的2倍,你应该知道怎么处理的吧。
end;
adotable1.Next;end;
begin
adotable1.first;//加这句,而且要保证30分钟内能执行完代码。
while not adotable1.eof do
begin
with adotable1 do
begin
edit;
fieldbyname('内容').asinteger := now-fieldbyname('以前日期').asdatetime;//在内容右边少了但引号???
//如果结果为小数或等于实际值的2倍,你应该知道怎么处理的吧。
end;
adotable1.Next;
end;
end;
begin
adotable1.first;//加这句,而且要保证30分钟内能执行完代码。
while not adotable1.eof do
begin
with adotable1 do
begin
edit;
fieldbyname('内容').asinteger := now-fieldbyname('以前日期').asdatetime;//在内容右边少了但引号???
//如果结果为小数或等于实际值的2倍,你应该知道怎么处理的吧。
post;
end;
adotable1.Next;
end;
end;
编译时出错
[Error] Unit1.pas(263): Incompatible types: 'Integer' and 'Extended'
fieldbyname('费用').asinteger :=Trunc(now-fieldbyname('以前日期').asdatetime);
楼主上面是整数和实数间不匹配的错了!