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 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
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
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
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 > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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);
|
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...
|
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
|
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...
| |
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,...
|
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."}
|
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
|
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...
|
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
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |