String was not recognized as a valid DateTime.

(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.
1jawsAsked:
Who is Participating?
 
wdosanjosConnect With a Mentor Commented:
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
 
wdosanjosCommented:
Please provide the value of DOB on the above example.
0
 
1jawsAuthor Commented:
19730130
0
 
1jawsAuthor Commented:
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
 
1jawsAuthor Commented:
sorry it was my fault, my validation was not working.. thanks for your effort.
0
All Courses

From novice to tech pro — start learning today.