• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 121
  • Last Modified:

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
0
allanlorriman
Asked:
allanlorriman
  • 4
  • 3
1 Solution
 
É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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now