[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

String was not recognized as a valid DateTime.

Posted on 2012-04-05
5
Medium Priority
?
456 Views
Last Modified: 2012-04-05
(ddYear.SelectedItem.Text + ddMonth.SelectedItem.Text + ddDay.SelectedItem.Text)

on my function I referenced as this
 public static int CreateNewUser( string DOB)
newUser.DOB = DateTime.Parse(DOB);

giving me error saying String was not recognized as a valid DateTime.
0
Comment
Question by:1jaws
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37812906
Please provide the value of DOB on the above example.
0
 

Author Comment

by:1jaws
ID: 37812927
19730130
0
 

Author Comment

by:1jaws
ID: 37812944
i added this to code (ddYear.SelectedItem.Text + "-" + ddMonth.SelectedItem.Text + "-" + ddDay.SelectedItem.Text)

and now, sometimes I get that error , sometimes it goes thru ok.. Weird.
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 total points
ID: 37812988
Try this:
public static int CreateNewUser( string DOB)
     newUser.DOB = DateTime.ParseExact(DOB, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);

Open in new window


DateTime.Parse tries to guess the date format of the string, when it cannot it fails.  That's why it works some times.
0
 

Author Comment

by:1jaws
ID: 37812999
sorry it was my fault, my validation was not working.. thanks for your effort.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

834 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