-2

I have a database table called 'student_details'.It contains a coloumn -'token_timestamp'. I want to find out the difference between current time and this 'token_timestamp' .It shouldnt be greater than 80minutes. What should i written in 'where' condition? Please help

    SqlCommand cmd=new SqlCommand("select student_id from student_details where  ??? ,con1);
nsds
  • 961
  • 4
  • 13
  • 39
  • your token_timestamp contains only time r it contains date and time both give example what it contain. – Amit Singh Apr 26 '13 at 09:42
  • showing only current_time like 10.00 AM (i have inserted it using DateTime.Now.ToShortTimeString() ) – nsds Apr 26 '13 at 09:47
  • DateTime.Now.ToShortTimeString() returns only date part....like this....4/26/2013..there no time. IF U ADD THIS THIN IT GOES LIKE .4/26/2013 00:00:00:00 .check your db WHAT IS STORED THERE – Amit Singh Apr 26 '13 at 09:50
  • no it shows like 15:29:53 – nsds Apr 26 '13 at 10:00
  • possible duplicate of [this](http://stackoverflow.com/questions/13577898/sql-time-difference-between-two-dates-result-in-hhmmss) – Shafqat Masood Apr 26 '13 at 10:07
  • no it not duplicate bcz his column dosnt have date part....uit contains only time – Amit Singh Apr 26 '13 at 10:23

1 Answers1

0

Try this...

 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);
Amit Singh
  • 8,039
  • 20
  • 29