Link to home
Start Free TrialLog in
Avatar of allanlorriman
allanlorriman

asked on

date exception - vb.net

Further to my previous question

https://www.experts-exchange.com/questions/28490709/date-exception-vb-net.html

Please can you help me here?

thanks
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

you have accepted a comment in your other question. Isn't it working? What is left?
Avatar of allanlorriman
allanlorriman

ASKER

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

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
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
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

you need to put that code in a Try...catch because it may bomb!