date1 := '2012-05-30 20:00:00';
date2 := '2012-05-30 20:59:59';从sql数据库,选择这个时间段内符合条件的记录,怎么写?
select * from table where 字段>=date1 and 字段<=date2

解决方案 »

  1.   

    date1与date2是字符串
    SQL.Tet:='select * from table where 字段 between '+Quotedstr(date1)+' and '+Quotedstr(date2);date1与date2是日期
    SQL.Tet:='select * from table where 字段 between '+Quotedstr(DateTimeToStr(date1))+' and '+Quotedstr(DateTimeToStr(date2));或用参数形式:
    SQL.Tet:='select * from table where 字段 between :d1 and :d2';
    Parameters.ParamByName('d1').Value:=date1;
    Parameters.ParamByName('d2').Value:=date2;
      

  2.   


    select * from table Where 时间字段 Between date1 and date2
      

  3.   

    select * from table where 字段>='2012-05-30 20:00:00' and 字段<'2012-05-30 21:00:00'
      

  4.   

    select * from table where 字段>='2012-05-30 20:00:00' and 字段<'2012-05-30 21:00:00'
      

  5.   

    在某些指定格式的情况下可以用格式化日期
    Select CONVERT(char(12),Getdate(),104)
    Select CONVERT(char(12),Getdate(),112)
    Select CONVERT(char(12),Getdate(),114)
    Select CONVERT(char(12),Getdate(),120)