Hi i need to calculate the time between Login in the id and Logout in asp.net using c#
Hi i need to calculate the time between Login and Logout in asp.net using c#
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Krishna GaradRank #191 · 12.8K reputationPosted Mar 10, 2012, 2:25 AM EST
Mahesh ChandRank #1 · 393.3K reputationPosted Mar 10, 2012, 2:37 AM EST
If you do not know how to use a session in ASP.NET, please search this site for Session in ASP.NET.
SenthilkumarRank #387 · 6.5K reputationPosted Mar 10, 2012, 6:07 AM EST
After user logged in into the application (after entering user id and password then click on the button) you can store the logged in time of the user.
Session["LoggedInTime"] = DateTime.Now.ToString();
When the user logged out the application (you may have log out button) then you can get the current time
DateTime.Now
If you want to calculate the time difference between log in and log out then you have to subtract the current time minus session stored time.
DateTime dtLogin = (DateTime) Session["LoggedInTime"].ToString();
DateTime dtLogout = DateTime.Now;
DateDiff (DateInterval.Minute, dtLogin , dtLogout )
There you will get the time difference in minutes.
Mahesh ChandRank #1 · 393.3K reputationPosted Mar 10, 2012, 5:48 PM EST