I only have one time per entry a start time so I am not sure where timeSpan has come from unless I have to subtract the current time from midnight to display an answer
@SamuelCampbell - Why don't you post your code so we can take a look? It's really hard offering advice without knowing exactly what's going on. I know you posted the one line above, but more context and perhaps the class definition thanks.
If you want subtract 2 times, such as t3=t2-t1, you need to do this:
DateTime t1, t2;
TimeSpan t3;
t3 = t2.Subtract(t1);
var text = t3.ToString();
T3 needs to be a TimeSpan not a date time. The subtraction of two times is a time span not a time itself. as in 1:20 - 1:10 = 10 minutes. 10 minutes is not a time it is a time span.
Hope this helpful
Regards
Young Yang
Please mark the replies as answers if they help or unmark if not.
Feedback to us
SamuelCampbe...
Member
106 Points
103 Posts
Do I need a cast here?
Apr 27, 2012 01:37 PM|LINK
Error 1 Cannot implicitly convert type 'System.TimeSpan' to 'System.DateTime'
Time = r.Time
dharnendra
Contributor
2955 Points
551 Posts
Re: Do I need a cast here?
Apr 27, 2012 01:50 PM|LINK
refer link and try it out
http://stackoverflow.com/questions/1161807/in-c-how-do-you-convert-the-timespan-datatype-to-datetime
Technical Leader
GTL-Ahmedabad
ignatandrei
All-Star
135174 Points
21682 Posts
Moderator
MVP
Re: Do I need a cast here?
Apr 27, 2012 02:19 PM|LINK
timespan is a difference between 2 dates. How do you want to be converted to date?
For example, 1 hour ? But 1 minute?
SamuelCampbe...
Member
106 Points
103 Posts
Re: Do I need a cast here?
Apr 27, 2012 02:25 PM|LINK
A timeSpan is the result of a calculation between two dateTime(s)?
I only have a time in my database that I am trying to display in an <ul> @showList.Time
ignatandrei
All-Star
135174 Points
21682 Posts
Moderator
MVP
Re: Do I need a cast here?
Apr 27, 2012 02:46 PM|LINK
Yes - substraction.
SamuelCampbe...
Member
106 Points
103 Posts
Re: Do I need a cast here?
Apr 27, 2012 03:00 PM|LINK
I only have one time per entry a start time so I am not sure where timeSpan has come from unless I have to subtract the current time from midnight to display an answer
ignatandrei
All-Star
135174 Points
21682 Posts
Moderator
MVP
Re: Do I need a cast here?
Apr 27, 2012 03:07 PM|LINK
If you have the code, you should know ....
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Do I need a cast here?
Apr 27, 2012 04:41 PM|LINK
@SamuelCampbell - Why don't you post your code so we can take a look? It's really hard offering advice without knowing exactly what's going on. I know you posted the one line above, but more context and perhaps the class definition thanks.
Blog | Twitter : @Hattan
Young Yang -...
All-Star
21343 Points
1818 Posts
Microsoft
Re: Do I need a cast here?
May 04, 2012 08:33 AM|LINK
Hi
If you want subtract 2 times, such as t3=t2-t1, you need to do this:
T3 needs to be a TimeSpan not a date time. The subtraction of two times is a time span not a time itself. as in 1:20 - 1:10 = 10 minutes. 10 minutes is not a time it is a time span.
Hope this helpful
Regards
Young Yang
Feedback to us
Develop and promote your apps in Windows Store