By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

DateTime.Parse

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

"Paul Beckett" <pa**********@lineone.net> wrote in message
news:c1**********@hercules.btinternet.com...
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

Jul 21 '05 #2

P: n/a
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
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:OA****************@TK2MSFTNGP12.phx.gbl...
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.

"Paul Beckett" <pa**********@lineone.net> wrote in message
news:c1**********@hercules.btinternet.com...
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


Jul 21 '05 #3

P: n/a
I've sorted it out - you use

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

Thanks

"Paul Beckett" <pa**********@lineone.net> wrote in message
news:c1**********@hercules.btinternet.com...
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
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:OA****************@TK2MSFTNGP12.phx.gbl...
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.

"Paul Beckett" <pa**********@lineone.net> wrote in message
news:c1**********@hercules.btinternet.com...
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



Jul 21 '05 #4

P: n/a
I see, you didn't so much want to prevent error but rather wanted to create
a date from a non-standard format.

"Paul Beckett" <pa**********@lineone.net> wrote in message
news:c1**********@hercules.btinternet.com...
I've sorted it out - you use

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

Thanks

"Paul Beckett" <pa**********@lineone.net> wrote in message
news:c1**********@hercules.btinternet.com...
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
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:OA****************@TK2MSFTNGP12.phx.gbl...
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.

"Paul Beckett" <pa**********@lineone.net> wrote in message
news:c1**********@hercules.btinternet.com...
> 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
>
>



Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.