Click here to Skip to main content
13,287,573 members (47,163 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i have store login_time and logout_time in 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
Updated 7-Jan-13 9:26am

1 solution

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

Solution 1

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.
__TR__ 7-Jan-13 14:10pm
Was about to post the same solution.
I guess you read my mind and posted it :laugh:
Marcus Kramer 7-Jan-13 14:11pm
+5. Same thing I was going to say.
OriginalGriff 7-Jan-13 14:14pm
Damn! There must be a hole in my tin-foil helmet...:laugh:
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2017
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