Solved

String was not recognized as a valid DateTime.

Posted on 2012-04-05
5
442 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 500 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

831 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