473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DateTime.Parse

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
4 1837
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: ChrisM | last post by:
Could anyone please tell me the difference between these 2 lines: myDate = DateTime.Now; and myDate = DateTime.Parse(DateTime.Now.ToString("dd/MM/yyyy")); Seeing as later on in the...
1
by: vooose | last post by:
Consider an application which has *many* references to DateTime.Parse(string); Is there a way, say when the application first starts up to force this method to use a specific IFormatProvider,...
4
by: Hans Merkl | last post by:
Does anybody know of a library that can handle strings pf various formats and conver them to a DateTime value? The strings are coming from a webform and I can't restrict the input (it's not my...
6
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference...
38
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
11
by: Tim | last post by:
Hi, I am trying to do something simple. Convert a string date to datetime but it is not working and is giving me a baffling error! System.Convert.ToDateTime("Jan 30, 2006")...
4
by: tshad | last post by:
Is there any difference between convert.ToDateTime and System.DateTime.Parse? I am using them both and they seem the same. Is one better to use than another? Thanks, Tom
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
4
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am having a problem formatting a string when the time is in format hh.mm.ss - used in Europe Parse seems ok when the date uses "/" or "." as seperator but I get an exception when time...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.