中易网

SQL语句中的时间计算加比较问题。

答案:2  悬赏:60  
解决时间 2021-04-28 02:53
  • 提问者网友:晨熙污妖王
  • 2021-04-27 07:54
string sqltime = " select lastlogin from usersinfo where id = '" + userid + "'";//定义一个SQL语句,从sersinfo中读取当前用户的最后登录时间。
DateTime lstime = DateTime.Parse(DB.Readstr(sqltime, 0));//DB是自定义的一个类,Readstr是类中的一个方法,用于读取数据表中某个字段的值。并转换成时间类型。
DateTime ls = lstime.AddMinutes(60);// 将读取出的时间加上60分钟。
现在我要读取 ls 这个时间数据大于当前时间的记录。用了这样一个SQL语句:
string grxx = "select * from usersinfo where '" + ls + "' > '" + datetime.now+ "' " ;
报错:where附近有语法错误.
如果我用datediff(mm, vipstart,getdate() ) 这个函数来判断,但是这个函数的第二个参数要求是字段。我的要求是在字段上加上60分钟。才与现在时间比较。所以两种方法都无法实现我的目的。请各们老师指教。学生万分感谢。
最佳答案
  • 二级知识专家网友:悲观垃圾
  • 2021-04-27 08:42
string sqltime = "select * from usersinfo where lastlogin > dateadd(minute,-60,getdate()) and id ="'+userid +"'";
全部回答
  • 1楼网友:余生继续浪
  • 2021-04-27 08:51
select a.b from (select tochar(sysdate,"yyyydmmdd")-出生日期 b from table) a where a.b < 30 把系统时间转换一下就可以了,不明白再问我,谢谢!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息