Solved

Treying to convert string to TimeSpan in C#

Posted on 2012-03-30
3
1,251 Views
Last Modified: 2012-04-04
Is there a reason why this doesn't work ? It says its not recognize as a valid TimeSpan. In the end I need to insert into a SQL Server time(7) field. How to do ? Any advice would be most appreciated.

TimeSpan timeSpanCompTime = new System.TimeSpan();
timeSpanCompTime=TimeSpan.Parse("08:00 AM");



Jason
0
Comment
Question by:jazzcatone
3 Comments
 
LVL 27

Expert Comment

by:Chinmay Patel
Comment Utility
Hi Jason,

I don't have access to an IDE right now but a TimeSpan will not take 8.00 AM as a valid parameter. It has to be a timespan, and you are specifyting time itself.

It can be 8 hours it can not be 8.00 AM.

Check : http://msdn.microsoft.com/en-us/library/se73z7b9(v=vs.71).aspx

Regards,
Chinmay.
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
Use DateTime.Parse and grab the value of TimeOfDay from the resulting DateTime object.

e.g.

TimeSpan timeSpanCompTime = new System.TimeSpan();
timeSpanCompTime=DateTime.Parse("08:00 AM").TimeOfDay;

Open in new window

0
 

Author Closing Comment

by:jazzcatone
Comment Utility
Perfect. Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now