Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Valid Date

In the code below is there a way to see if the selection is a valid date?
return a message if it's an invalid date or ir a field hasn't been selected.

DateTime.Parse(carPickupMonth.SelectedValue & " " & carPickupDay.SelectedValue & ", " & carPickupYear.SelectedValue)
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg 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
You can also use "TryParse" instead of using a try/catch bloc.

http://msdn.microsoft.com/en-us/library/system.datetime.tryparse.aspx
bool valid_date = false;
DateTime dt;
if (!DateTime.TryParse("", out dt))
  valid_date = false;
//There the "dt" variable containt the datetime value 

Open in new window

My example was in C# and you should it should be that
if (!DateTime.TryParse(carPickupMonth.SelectedValue + " " + carPickupDay.SelectedValue + ", " + carPickupYear.SelectedValue, out dt))

Open in new window

Avatar of Larry Brister

ASKER

Hey guys,
  I work in VB and am getting errors on code conversion tools online with your code.  It's looking for a "}" somewhere.
SOLUTION
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