Click here to Skip to main content
11,796,393 members (71,359 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 7:50am
Edited 7-Jan-13 8: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__ at 7-Jan-13 14:10pm
Was about to post the same solution.
I guess you read my mind and posted it :laugh:
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.
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)

  Print Answers RSS
0 Maciej Los 530
1 Abhinav S 392
2 OriginalGriff 340
3 CPallini 269
4 KrunalRohit 249
0 OriginalGriff 2,012
1 Maciej Los 1,615
2 KrunalRohit 1,310
3 CPallini 1,015
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web01 | 2.8.151002.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