date exception - vb.net

Further to my previous question

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28490709.html

Please can you help me here?

thanks
allanlorrimanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
you have accepted a comment in your other question. Isn't it working? What is left?
0
allanlorrimanAuthor Commented:
Hi Eric

the only first part works ie: Convert(DateTime, EndTime, 103)=Convert(DateTime, GetDate(), 103)

because I am passing the date to Age function, its giving me the same error...

To: .comSubject: Problem Updating the IQ Test Info. Session Complete - System.FormatException: The specified string is not in the form required for an e-mail address.
   at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName)
   at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset)
   at System.Net.Mail.MailAddressCollection.ParseValue(String addresses)
   at System.Net.Mail.MailAddressCollection.Add(String addresses)
   at System.Net.Mail.Message..ctor(String from, String to)
   at System.Net.Mail.MailMessage..ctor(String from, String to)
   at System.Net.Mail.MailMessage..ctor(String from, String to, String subject, String body)
   at WebFunctions.SendEmail(String From, String ToField, String Subject, String Body, Collection Attachment) in D:\Web Sites\www..com\App_Code\WebFunctions.vb:line 142Body:System.InvalidCastException: Conversion from string "26/03/1991" to type 'Date' is not valid.
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToDate(String Value)
   at OnlineTest_EndTest.Page_Load(Object sender, EventArgs e) in D:\Web Sites\www..com\IQTest\EndTest.aspx.vb:line 79

Open in new window

0
Éric MoreauSenior .Net ConsultantCommented:
If a date is stored as a date, you don't have issues. It seems here that you have dates stored in string with a d/m/y format which is not universal. Either convert to date or format as y/m/d
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

allanlorrimanAuthor Commented:
can I change this to date format?

ContactDetails.DateOfBirth

and pass it to IsPass function ?

converting would be an easy option.. please can you suggest the syntax?

thanks
0
Éric MoreauSenior .Net ConsultantCommented:
You can use ParseExact to convert a string to a date:

http://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
allanlorrimanAuthor Commented:
Ok thanks Eric, let me try.

Something like this?

      Dim DateString, DateFormat As String   
      Dim DateResult As Date 
      Dim DateProvider As CultureInfo = CultureInfo.InvariantCulture

      
      DateString =  ContactDetails.DateOfBirth
      DateFormat = "dd-mm-yyy" 
       
      DateResult = Date.ParseExact(DateString, DateFormat, DateProvider)


      GetResult = IsPass(CustomerID, TestID, GiftCodeID, DateResult )

Open in new window

0
Éric MoreauSenior .Net ConsultantCommented:
you need to put that code in a Try...catch because it may bomb!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.