Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 7-Jan-13 8:50am
Edited 7-Jan-13 9:26am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
SELECT DATEDIFF(second, logintime, logouttime) as loggedInSeconds FROM logininfo
 
If you really must store it, then you can use the same command:
 
UPDATE logininfo SET totaltime=DATEDIFF(second, logintime, logouttime)
 
But I wouldn't do it myself.
  Permalink  
Comments
__TR__ at 7-Jan-13 14:10pm
   
Was about to post the same solution.
I guess you read my mind and posted it :laugh:
+5
OriginalGriff at 7-Jan-13 14:14pm
   
Damn! There must be a hole in my tin-foil helmet...:laugh:
Sergey Alexandrovich Kryukov at 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
Marcus Kramer at 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)



Advertise | Privacy | Mobile
Web04 | 2.8.150326.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100