Forums » .NET » .NET »

How to convert a string to a timespan in C#.net?


Posted Date: 02 Feb 2008      Posted By:: Harsh     Member Level: Gold    Member Rank: 470     Points: 2   Responses: 1



I have a string which I want to convert toa time span object
eg.
string sDuration = "00:18:09";

Now I want to assign this value to a time span object.
eg.
TImeSpan ts = new TimeSpan();
ts = (TimeSpan)sDuration;

but this type cast is not working.




Responses

#259714    Author: satyaprakash      Member Level: Silver      Member Rank: 4571     Date: 04/Jul/2008   Rating: 2 out of 52 out of 5     Points: 4

TimeSpan timeSpan = new System.TimeSpan();
bool isTimeSpan = System.TimeSpan.TryParse(sDuration , out timeSpan); (if u r working in 2003 u wont have TryParse..u can use simply Parse method.TryParse returns false if the input string is not in correct format .)..

Try it.It works

Rohan


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : joins
Previous : tell me about cursor give me example pls
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John

Online Members

Priya jain
Mahe
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India