各位大哥是这样的,在我的数据库中有一个“登录时间”字段,存放的时用户登录的年月日时分秒如
2005-8-11 14:23:40 这个样子,现在我要取在数据库中日期为近一天的所有记录该怎么写啊
求一个这么写出的SQL语句
showstring="select * from 历史记录表 where (现在时间-登录时间)<=1 天 order by 登录时间 desc ";

解决方案 »

  1.   

    select * from 历史记录表 where convert(char(10),登录时间,120)=convert(char(10),dateadd(d,-1,getdate()),120)
      

  2.   

    SELECT * from 历史记录表 where DATEDIFF(day, 登陆时间字段, getdate())
      

  3.   

    select * from 历史记录表 where (cast(convert(char(10),现在时间,120) as datetime)-cast(convert(char(10),登录时间,120) as datetime))<=1 天 order by 登录时间 desc "