Click here to Skip to main content
16,021,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am storing Datetime in a session as mentioned below:-
C#
Session["LoggedInTime"] = System.DateTime.Now;

Then i m retrieving this value on a page load like this:-
C#
DateTime _loggedInTime = Convert.ToDateTime(Session["LoggedInTime"]);

I debug the above code code and find that up to here the _loggedInTIme is showing the correct date which i m storing in it. After that i m calculating the time span like this:-
C#
TimeSpan elapsedtimespan = System.DateTime.Now.Subtract(_loggedInTime);
int elapsedtime = Convert.ToInt32(elapsedtimespan.TotalSeconds);

I found while debugging the code that ,while subtraction the _loggedInTime = {1/1/0001 12:00:00 AM} and due to which i m not able to get exact elapsedtime .

Please help me to solve this issue as i m not getting why the _loggedInTime become {1/1/0001 12:00:00 AM} at calculating TimeSpan.
Posted

1 solution

Hi,

Try using DateTime.TryParse(). Follow the links if you are getting any difficulty
http://msdn.microsoft.com/en-us/library/ch92fbc1[^]
http://www.dotnetperls.com/datetime-tryparse[^]

All the best.
--AK
 
Share this answer
 

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