Check to see if a value is a DateTime

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top