[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

String was not recognized as a valid DateTime.

Posted on 2012-04-05
5
Medium Priority
?
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 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