473,748 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1860
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**********@l ineone.net> wrote in message
news:c1******** **@hercules.bti nternet.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.r illing.net> wrote in message
news:OA******** ********@TK2MSF TNGP12.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**********@l ineone.net> wrote in message
news:c1******** **@hercules.bti nternet.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.Data Item, "Date", "{0:dd MMM yyyy}") %>

Thanks

"Paul Beckett" <pa**********@l ineone.net> wrote in message
news:c1******** **@hercules.bti nternet.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.r illing.net> wrote in message
news:OA******** ********@TK2MSF TNGP12.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**********@l ineone.net> wrote in message
news:c1******** **@hercules.bti nternet.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**********@l ineone.net> wrote in message
news:c1******** **@hercules.bti nternet.com...
I've sorted it out - you use

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

Thanks

"Paul Beckett" <pa**********@l ineone.net> wrote in message
news:c1******** **@hercules.bti nternet.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.r illing.net> wrote in message
news:OA******** ********@TK2MSF TNGP12.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**********@l ineone.net> wrote in message
news:c1******** **@hercules.bti nternet.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
3743
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 code, the ExecuteNonQuery works with the first
1
13304
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, so every DateTime.Parse(string) is really DateTime.Parse(string, format);
4
18167
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 form). I have been using Convert.ToDateTime but it choked on "12:00 noon". I am looking for a function that can make sense out of anything that looks like a date/time. Outlook is pretty good at it when you enter an appointment with the GUI, but...
6
8989
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 between date and datetime classes? Please, help
38
807
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 FormatString, how can you convert the String back to a DateTime? DateTime.Parse(...) doesn't use the FormatString. Now admitedly, if the format string is just "MM", it can't be done. But if the format string is "yyyyMMdd", or "ddMMMyyyy hhmmsst", it...
11
7244
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 only that I have to listen to them because they know it better. They told also that in a business situation it is better to use datetime.parseexact for changing cultures and not to use the globalization setting. I did not give them this sample,...
11
2806
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") 'System.Convert.ToDateTime("Jan 30, 2006")' threw an exception of type 'System.IndexOutOfRangeException' base {System.SystemException}: {"Index was outside the bounds of the array."}
4
35894
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
5140
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. Could someone help me with the customization? Thanks. String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider...
4
3698
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 uses "." as seperator as used in Europe I have US regional setting and I have tried switching my regional setting to Europe
0
8984
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.