请问SQL语言中日期类型字段怎么比较?

idoloveyou 2003-10-18 10:59:30
表test中有一个time字段是日期类型,里面存放着创建这条记录的时间
现在想select出所有time在5天以前的所有记录,怎么写?
...全文
97 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuiniu 2003-10-18
  • 打赏
  • 举报
回复
笔误:
select * from test where time < cast(convert( char(10),getdate(),121) as datetime) - 5
shuiniu 2003-10-18
  • 打赏
  • 举报
回复
select * from test where time < getdate() - 5
or
select * from test where time < cast(convert( char(10),getdate(),121) as datetime) - 1
sdhdy 2003-10-18
  • 打赏
  • 举报
回复
select * from test where time<dateadd(dd,-5,getdate())
ysycrazy 2003-10-18
  • 打赏
  • 举报
回复
select * from test where time<dateadd(day,-5,getdate())
sshh119 2003-10-18
  • 打赏
  • 举报
回复
八日期分解了,date-5天再组合
welyngj 2003-10-18
  • 打赏
  • 举报
回复
select * from tablename where DATEDIFF(day, time, getdate())>5

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧