求间隔半小时数据 的处理方法。

来源:互联网 发布:mysql insert字段 编辑:程序博客网 时间:2024/05/17 03:48

procedure TForm1.Button1Click(Sender: TObject);

var

 s,stime, stime1 :string;

begin

 stime := formatDateTime('YYYY-MM-DD HH:MM:SS',self.DateTimePicker1.DateTime);

 //stime := Copy(stime,

 sTime := IntToStr(StrToInt(Copy(stime,15,2)) + 30) ;

 if StrToInt(sTime) > 60 then begin

    sTime := IntToStr(StrToInt(sTime) - 60); //超过减60

    if Length(sTime) < 2 then STime := '0'+STime;//补足两位

 end;

 

 if StrToInt(stime) - 30 < 0 then

    stime1 := IntTOStr(StrToInt(stime)+ 30)

 else

    stime1 := IntTOStr(StrToInt(stime) - 30); //求另一个数值

 if Length(stime1) < 2 then sTime1 := '0'+stime1;

 s := 'SELECT * FROM table1 WHERE  substring(CONVERT(VARCHAR(19),dttime,20),15,2) =' + ''''+stime+'''';

 s := s + ' OR substring(CONVERT(VARCHAR(19),dttime,20),15,2) =' + ''''+stime1+'''';

 self.ADOQuery1.SQL.Text := s ;

 try

   self.ADOQuery1.Open;

 except

 

 end;

end;

原创粉丝点击