Check to see if a value is a DateTime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

I've written the below but am aware it's not the best way to do it. Does
anyone have any other example please? The method simply checks to see if the
value is a date.

try
{
p.Value = DateTime.Parse(coll.Get(i)).ToString("yyyy-MM-dd");
}
catch
{
p.Value = coll.Get(i);
}

Thanks all,

Jon
 
howdy

dim date as String = String.Empty
dim value as Object = coll.Get(i)

if typeof value is DateTime then
date = CType(value, DateTime).ToString("yyyy-MM-dd")
end if

hope this helps

VB.Net has an IsDate() function that checks if the value is a date.
 
Back
Top