Click here to Skip to main content
16,020,378 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I Am trying to calculate number of working hours of an employee... Please Help me to retrieve from this error :( :( :(

Following code i used....
C#
DateTime inTime = Session["time"];
DateTime outTime = DateTime.Now;//or Get ur out time from ur logic
TimeSpan span = outTime.Subtract(inTime);
TextBox1.Text = span.Seconds.ToString();

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0266: Cannot implicitly convert type 'object' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)
Posted
Updated 1-Mar-13 3:17am
v2
Comments
Thenmozhi D 1-Mar-13 9:03am    
solved :) :)

DateTime inTime = (DateTime)Session["time"];
DateTime outTime = DateTime.Now;
TimeSpan span = outTime.Subtract(inTime);
TextBox1.Text = span.Seconds.ToString();
Sergey Alexandrovich Kryukov 12-Mar-13 14:27pm    
Improve it by the advice given in Solution 1. (I advise you to accept it formally (green button)).

By the way, thank you for not posting it as an "answer", as some do...
—SA

TimeSpan span = outTime - inTime;
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Mar-13 14:26pm    
By all measures better then OP's "Subtract", a 5.
—SA
fjdiewornncalwe 12-Mar-13 16:31pm    
Thanks, Sergey.
Compiler Error Message: CS0266: Cannot implicitly convert type 'object' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?) .
Read your Exception:

DateTime inTime = (DateTime) Session["time"];

And you should check if the Session is null.
 
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