Validate Date before casting

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hi,

I have what is probabally a date contained in an object variable.
Before casting to date I actually want to attempt to verify that I actually
have a date.
I prefer to do this before casting as I do not want to generate an exception
if the object is NOT a date.
VB has the IsDate() function.. Is there an equivilent in c#, I'd prefer not
to have to reference the vb library just for this function.

cheers

martin.
 
Martin,

object time = DateTime.Now;

bool isDate = (time.GetType() == typeof(DateTime));

Is this enough?

HTH,
Alexander Shirshov
 
Martin,

You can set the parse in a try catch block. Probably (almost sure) is in
VBNet the same done with the IsDate.

Cor
 
Thanks for the solution,

I guess that I can use this to test any variable types.

cheers

martin.
 
Back
Top