2013-04-26 67 views
-1

我有一个名为'student_details'的数据库表。它包含一个coloumn -'token_timestamp'。我想知道当前时间和这个'token_timestamp'之间的区别,它不应该大于80分钟。我应该写什么'在哪里'的条件?请帮助用于查找两次差异的MS SQL查询?

SqlCommand cmd=new SqlCommand("select student_id from student_details where ??? ,con1); 
+0

您token_timestamp只包含时间R它包含日期和时间均可以得到例如它所包含的内容。 – 2013-04-26 09:42:45

+0

只显示current_time像10.00 AM(我插入它使用DateTime.Now.ToShortTimeString()) – nsds 2013-04-26 09:47:03

+0

DateTime.Now.ToShortTimeString()只返回日期部分....像这样.... 4/26/2013 ..没有时间。如果你添加了这个薄薄的东西,就像.4/26/2013 00:00:00:00。检查你的数据库什么被存储在那里 – 2013-04-26 09:50:36

回答

0

尝试......

SqlCommand cmd=new SqlCommand("select student_id from student_details where 
    DateDiff(minute,Cast(token_timestamp as smalldatetime),CAST(cast(GetDate() as time) as smalldatetime))>80" 
    ,con1); 
+0

我编辑我的答案现在尝试... – 2013-04-26 11:04:44