1

I have a problem in this line of code:

Dim arrivalDate As Date = Request.Form("startDate")

the error is this: "Conversion from string "" to type 'Date' is not valid."

jdoe1111
  • 33
  • 4

2 Answers2

3

You need to parse the string value to a date.

Dim arrivalDate As DateTime = DateTime.Parse(Request.Form("startDate"))

See the following MSDN for more details.

Also if you are unsure of the validity of the startDate value (not sure if the string is actually a valid date) you can call TryParse like so:

Dim dateValue As Date

If Date.TryParse(Request.Form("startDate"), dateValue) Then
            //Do something
Luke Stoward
  • 1,200
  • 12
  • 22
2

use TryParse always to eliminate runtime exception

Dim arrivalDate As Date
Date.TryParse(Request.Form("startDate"), arrivalDate)

if the value of Request.Form("startDate") is not a valid date then arrivalDate will have the value of Date.MinValue So have a check before performing further operations

Akshay Gaonkar
  • 541
  • 3
  • 20