Solved

String was not recognized as a valid DateTime.

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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