Click here to Skip to main content
15,910,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have store login_time and logout_time in table.now i have to store difference of logout_time-login_time intable.what i can do.i have try following but i can't do...

SqlCommand cmd3 = new SqlCommand("update logininfo set totaltime=logouttime-logintime where log_id=" + logid, cnn);
Posted
Updated 7-Jan-13 8:26am
v2

1 solution

Why?
Why store something that you have already, in the sense that you can calculate it whenever you need to? Storing it as separate information just increases your database size and provides a route for error to creep in - as it does - when somehow the difference between the In and Out times, and the stores value do not match.

SQL
SELECT DATEDIFF(second, logintime, logouttime) as loggedInSeconds FROM logininfo


If you really must store it, then you can use the same command:

SQL
UPDATE logininfo SET totaltime=DATEDIFF(second, logintime, logouttime)


But I wouldn't do it myself.
 
Share this answer
 
Comments
__TR__ 7-Jan-13 14:10pm    
Was about to post the same solution.
I guess you read my mind and posted it :laugh:
+5
OriginalGriff 7-Jan-13 14:14pm    
Damn! There must be a hole in my tin-foil helmet...:laugh:
Sergey Alexandrovich Kryukov 7-Jan-13 15:44pm    
No, you just miscalculated the skin layer thickness, for such a high-frequency radiation. You just need to use thicker foil for your helmet. Upgrade it as soon as possible, as I'm already sensing what you are up to... (don't worry, I won't tell anyone). My 5, by the way.
—SA
fjdiewornncalwe 7-Jan-13 14:11pm    
+5. Same thing I was going to say.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900