在delphi中我想用一下系统时间减去另一个时间怎么写啊?谢谢? 在delphi中我想用一下系统时间减去另一个时间怎么写啊?谢谢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var d : TDateTime; days : integer;begin d := StrToDate('2003-1-1'); days := Date() - d; ShowMessage(Format('相差%d天',[days]));end; var t,t1, t2: TDateTime; begint1:=now;t = TDateTime(t1 - t2)end; 然后用DecodeTime分解时间 我要与系统时间比较的时间是我从query中查出来的日期型字段。怎么写啊?谢谢!! var t,t1, t2: TDateTime; begint1:=now;t2:=query1.fieldbyname('datetime').asdatetime;t = TDateTime(t1 - t2)end; 然后用DecodeTime分解时间 你告诉我的不对t = TDateTime(t1 - t2)? var nYear, nMonth, nDay: Word; oYear, oMonth, oDay: Word;begin DecodeDate(query1.fieldbyname('查询时间').AsDateTime,oYear, oMonth, oDay); DecodeDate(now,nYear, nMonth, nDay); n:=nyear-oyear;//相差的年数 m:=n*12+nyear-oyear;//相差的月数 d:=n*365+m*30+nday-oday;//相差的天数(这里只是举个例子,相差的天数这样不对的) var nYear, nMonth, nDay: Word; oYear, oMonth, oDay: Word; m,n,d:Integer;begin DecodeDate(query1.fieldbyname('查询时间').AsDateTime,oYear, oMonth, oDay); DecodeDate(now,nYear, nMonth, nDay); n:=nyear-oyear;//相差的年数 m:=n*12+nyear-oyear;//相差的月数 d:=VarToInt(now-query1.fieldbyname('查询时间').AsDateTime);//相差的天数可以这样 //得到 to zwhu 您的我照您写的在WIN2000+D6下试了一下, 其中 VARTOINT函数是怎么得来的?我查了DELPHI的帮助,没有这个函数啊. 不好意思,可以:StrToInt(VarToInt(now-query1.fieldbyname('查询时间').AsDateTime));相差的秒数可以:procedure TForm1.Button1Click(Sender: TObject);var nYear, nMonth, nDay: Word; oYear, oMonth, oDay: Word; m,n,d:Integer; nHour, nMin, nSec, nMSec: Word; oHour, oMin, oSec, oMSec: Word; s:String;//要的秒数begin DecodeDate(strtodatetime('2004-01-29'),oYear, oMonth, oDay); DecodeDate(now,nYear, nMonth, nDay); n:=nyear-oyear;//相差的年数 m:=n*12+nyear-oyear;//相差的月数 d:=StrToInt(VarToStr(date-strtodate('2004-01-29'))); decodetime(Now,nHour,nMin,nSec,nMSec); decodetime(strtodatetime('2004-01-28'),oHour,oMin,oSec,oMSec); s:=vartostr(d*24*3600+(nHour-oHour)*3600+(nMin-oMin)*60+nSec-oSec); showmessage(s);end;以上调试在win2000+delphi6通过,你只要把'2004-01-28'修改成你的数据库查询出来的时间即可 var nYear, nMonth, nDay: Word; oYear, oMonth, oDay: Word; m,n,d:Integer; nHour, nMin, nSec, nMSec: Word; oHour, oMin, oSec, oMSec: Word; s:String;//要的秒数begin DecodeDate(query1.FieldByName('所查询时间').AsDateTime,oYear, oMonth, oDay); DecodeDate(now,nYear, nMonth, nDay); n:=nyear-oyear;//相差的年数 m:=n*12+nyear-oyear;//相差的月数 d:=StrToInt(VarToStr(date-query1.FieldByName('所查询时间').AsDate)); decodetime(Now,nHour,nMin,nSec,nMSec); decodetime(query1.FieldByName('所查询时间').AsDateTime,oHour,oMin,oSec,oMSec); s:=vartostr(d*24*3600+(nHour-oHour)*3600+(nMin-oMin)*60+nSec-oSec); showmessage(s);写的匆忙,呵。。 zwhu(心灵琴音) 你好!!!你看看一下我的(? 小弟有问题请大哥们帮忙!!谢谢!! (lzd1024 ))这个帖子你是高手。帮帮老弟。谢谢了!!!!!! 我看了,应该是sql语句少了逗号了吧,呵,终于发现有人和我一样粗心了,不知道是不是哦 怎么样获得当前屏幕某一坐标的RGB值 请指点阿 如何在A窗口移动时控制其他窗口移动 我的dbgrid怎么没数据上来?(对不起,我没分了^_^) 关于软件加密和注册 Oracle客户端连接问题!谢谢! 能动态定义多维数组吗? 再请教伪装IP问题(接收) 菜鸟向各位高手求助! Ehlib 的 DBGridEh 控件怎样才能像 dxDBGrid 控件那样输出文件到 EXCEL ? 一个文本文件用delphi程序怎么把它清空? 请帮我看一下下面的程序数据库连接为何会出错? ◆◆急聘DELPHI程序员◆◆(班主请保留一天,真的要人)
d : TDateTime;
days : integer;
begin
d := StrToDate('2003-1-1');
days := Date() - d;
ShowMessage(Format('相差%d天',[days]));
end;
t,t1, t2: TDateTime;
begin
t1:=now;
t = TDateTime(t1 - t2)
end;
然后用DecodeTime分解时间
谢谢!!
t,t1, t2: TDateTime;
begin
t1:=now;
t2:=query1.fieldbyname('datetime').asdatetime;
t = TDateTime(t1 - t2)
end;
然后用DecodeTime分解时间
oYear, oMonth, oDay: Word;
begin DecodeDate(query1.fieldbyname('查询时间').AsDateTime,oYear, oMonth, oDay);
DecodeDate(now,nYear, nMonth, nDay);
n:=nyear-oyear;//相差的年数 m:=n*12+nyear-oyear;//相差的月数 d:=n*365+m*30+nday-oday;//相差的天数(这里只是举个例子,相差的天数这样不对的)
oYear, oMonth, oDay: Word;
m,n,d:Integer;
begin DecodeDate(query1.fieldbyname('查询时间').AsDateTime,oYear, oMonth, oDay);
DecodeDate(now,nYear, nMonth, nDay);
n:=nyear-oyear;//相差的年数 m:=n*12+nyear-oyear;//相差的月数 d:=VarToInt(now-query1.fieldbyname('查询时间').AsDateTime);//相差的天数可以这样
//得到
您的我照您写的在WIN2000+D6下试了一下,
其中 VARTOINT函数是怎么得来的?我查了DELPHI的帮助,没有这个函数啊.
procedure TForm1.Button1Click(Sender: TObject);
var nYear, nMonth, nDay: Word;
oYear, oMonth, oDay: Word;
m,n,d:Integer;
nHour, nMin, nSec, nMSec: Word;
oHour, oMin, oSec, oMSec: Word;
s:String;//要的秒数
begin
DecodeDate(strtodatetime('2004-01-29'),oYear, oMonth, oDay);
DecodeDate(now,nYear, nMonth, nDay);
n:=nyear-oyear;//相差的年数
m:=n*12+nyear-oyear;//相差的月数
d:=StrToInt(VarToStr(date-strtodate('2004-01-29'))); decodetime(Now,nHour,nMin,nSec,nMSec);
decodetime(strtodatetime('2004-01-28'),oHour,oMin,oSec,oMSec);
s:=vartostr(d*24*3600+(nHour-oHour)*3600+(nMin-oMin)*60+nSec-oSec);
showmessage(s);
end;以上调试在win2000+delphi6通过,你只要把'2004-01-28'修改成你的数据库查询出来的时间即可
oYear, oMonth, oDay: Word;
m,n,d:Integer;
nHour, nMin, nSec, nMSec: Word;
oHour, oMin, oSec, oMSec: Word;
s:String;//要的秒数
begin
DecodeDate(query1.FieldByName('所查询时间').AsDateTime,oYear, oMonth, oDay);
DecodeDate(now,nYear, nMonth, nDay);
n:=nyear-oyear;//相差的年数
m:=n*12+nyear-oyear;//相差的月数
d:=StrToInt(VarToStr(date-query1.FieldByName('所查询时间').AsDate)); decodetime(Now,nHour,nMin,nSec,nMSec);
decodetime(query1.FieldByName('所查询时间').AsDateTime,oHour,oMin,oSec,oMSec);
s:=vartostr(d*24*3600+(nHour-oHour)*3600+(nMin-oMin)*60+nSec-oSec);
showmessage(s);写的匆忙,呵。。
你看看一下我的(? 小弟有问题请大哥们帮忙!!谢谢!! (lzd1024 ))这个帖子
你是高手。帮帮老弟。谢谢了!!!!!!