Select * from Result Where DateTime >"2012-01-03 00:00:01" and DateTime < "2012-01-04 23:59:59" DateTime变量类型,2012之前的数据记录是到2011年12-27号截止,都可以查询到,然后我今天有1月3号的记录,数据库里明明有,可是就是看不到,我在数据库的查询器直接用语句也查不到,但是换成前面的日期就可以了,郁闷
Select * from Result Where DateTime >"2012-01-03 00:00:01" and DateTime < "2012-01-04 23:59:59"你用了关键字吧,,Sql字段这么命名合适不? Select * from Result Where [DateTime] >"2012-01-03 00:00:01" and [DateTime] < "2012-01-04 23:59:59" 试试?
在delphi的SysUtils单元里面有这么一个函数可以实现字符串转datetime:function StrToDateTime(const S: string): TDateTime; begin if not TryStrToDateTime(S, Result) then ConvertErrorFmt(@SInvalidDateTime, [S]); end;
Select * from Result Where [DateTime] >"2012-01-03 00:00:01" and [DateTime] < "2012-01-04 23:59:59"
试试?
begin
if not TryStrToDateTime(S, Result) then
ConvertErrorFmt(@SInvalidDateTime, [S]);
end;