DateTime.Parse

  • Thread starter Thread starter Paul Beckett
  • Start date Start date
P

Paul Beckett

Does anyone know how to prevent an error when using DateTime.Parse?

I am using it to format the display of dates in my database. However, some
dates are empty and so I get an error when I try to run my webpage.

Help please!!

paul Beckett
 
You can't prevent an error. Obviously if you try to turn "acbxyz" into a
date you will get an error.

You need to catch it in a try...catch block.

A better way might be to test prior to calling Parse to see if your value is
an empty string, then just don't call Parse.
 
All I really want to do is prevent the date appearing as, say, 20/02/2004
00:00:00

There must (surely) be an easy way to do this??

Paul
 
I've sorted it out - you use

<%# DataBinder.Eval(Container.DataItem, "Date", "{0:dd MMM yyyy}") %>

Thanks
 
I see, you didn't so much want to prevent error but rather wanted to create
a date from a non-standard format.
 
Back
Top