troubleshooting Question

C# parse DateTime

Avatar of Ricky White
Ricky WhiteFlag for United States of America asked on
C#.NET ProgrammingVisual Basic.NET
7 Comments2 Solutions977 ViewsLast Modified:
Hi,

**********************************************************
string str = "20081231113000"

ApplicationDate = DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
****************************************************************
The above code works fine and provides the application date in the format that I need. However sometimes str is blank. In that case the program throws an exception that the string is in invalid format.

How can I change this code so that it will parse and give me the date if available and if the date is unavailable assigns a value of null or minvalue for the applicationdate.

Would a Try Catch be a good approach? or is there a better way?

Thanks
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros