2013-04-26 28 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