Solved

String was not recognized as a valid DateTime.

Posted on 2012-04-05
5
439 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
Comment Utility
Please provide the value of DOB on the above example.
0
 

Author Comment

by:1jaws
Comment Utility
19730130
0
 

Author Comment

by:1jaws
Comment Utility
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
Comment Utility
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
Comment Utility
sorry it was my fault, my validation was not working.. thanks for your effort.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now