473,809 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime.ParseE xact( ) Exception

I'm trying to parse a string into a DateTime object. I
want to try using ParseExact to see if I can improve
performance of a frequently-called method (i.e., please
don't suggest using Parse()). My code looks like this:

IFormatProvider fp = new System.Globaliz ation.CultureIn fo
("en-US");
DateTime dt = DateTime.ParseE xact("Mar 9, 2005", "MMM d,
yyyy", fp);

This throws an exception in MatchAbbreviate dMonthName()
(an FCL method). If I look at the CultureInfo object,
there is, in fact, a month called "Mar".

How can I use my custom format with ParseExact?

Thanks!

Dave P.

Nov 16 '05 #1
3 7792
Dave,
That is very odd - I just tried the code snippet on my machine and it worked
fine?

What version of the Framework are you using? Also, what OS?

--
Nathan

"Dave P." <an*******@disc ussions.microso ft.com> wrote in message
news:70******** *************** *****@phx.gbl.. .
I'm trying to parse a string into a DateTime object. I
want to try using ParseExact to see if I can improve
performance of a frequently-called method (i.e., please
don't suggest using Parse()). My code looks like this:

IFormatProvider fp = new System.Globaliz ation.CultureIn fo
("en-US");
DateTime dt = DateTime.ParseE xact("Mar 9, 2005", "MMM d,
yyyy", fp);

This throws an exception in MatchAbbreviate dMonthName()
(an FCL method). If I look at the CultureInfo object,
there is, in fact, a month called "Mar".

How can I use my custom format with ParseExact?

Thanks!

Dave P.

Nov 16 '05 #2
Dave P. <an*******@disc ussions.microso ft.com> wrote:
I'm trying to parse a string into a DateTime object. I
want to try using ParseExact to see if I can improve
performance of a frequently-called method (i.e., please
don't suggest using Parse()). My code looks like this:

IFormatProvider fp = new System.Globaliz ation.CultureIn fo
("en-US");
DateTime dt = DateTime.ParseE xact("Mar 9, 2005", "MMM d,
yyyy", fp);

This throws an exception in MatchAbbreviate dMonthName()
(an FCL method). If I look at the CultureInfo object,
there is, in fact, a month called "Mar".

How can I use my custom format with ParseExact?


Like Nathan, it works for me. What exception is thrown? Have you tried
searching for it on Google?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
FCL version 1.1, OS Win2k server.

I don't have repro handy at the moment, but the exception
was FormatException , I think. Whatever it was, it was an
indication that the format string could not be used for
the date string.

I have done a Google search on this and haven't found
anything, which is why I'm posting here. But always a
good idea.

Dave
-----Original Message-----
Dave,
That is very odd - I just tried the code snippet on my machine and it workedfine?

What version of the Framework are you using? Also, what OS?
--
Nathan

"Dave P." <an*******@disc ussions.microso ft.com> wrote in messagenews:70******* *************** ******@phx.gbl. ..
I'm trying to parse a string into a DateTime object. I
want to try using ParseExact to see if I can improve
performance of a frequently-called method (i.e., please
don't suggest using Parse()). My code looks like this:

IFormatProvider fp = new System.Globaliz ation.CultureIn fo ("en-US");
DateTime dt = DateTime.ParseE xact("Mar 9, 2005", "MMM d,
yyyy", fp);

This throws an exception in MatchAbbreviate dMonthName()
(an FCL method). If I look at the CultureInfo object,
there is, in fact, a month called "Mar".

How can I use my custom format with ParseExact?

Thanks!

Dave P.

.

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
6990
by: Dan S | last post by:
My application asks the user to enter in a date - in the mm/dd/yyyy format. Is there any quick and easy way to verify the date the user enters is formatted correctly? Right now I'm calling DateTime.Parse() and catching the FormatException but it seems this is a bit inefficient - catching the exception that is. There is some pretty obvious delay while it traces back up the call stack. Is there a better way? Something that returns a bool...
4
1216
by: help | last post by:
If I enable debug at C# exceptions, it dutifully breaks and shows me the stack of called procedures. At the top (of my list) is DateTime.ParseExact() and it does through an exception if I proceed. But, how can I examine the parameters to that call to see what it doesn't like? tnx, /steveA
4
18173
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...
5
1749
by: ramon.smits | last post by:
I'm trying to get the following date/time string formatted. But I don't succeed. I get an exception saying the date/time string is invalid. string input = "8/09/05 9:27a"; string format = "M/dd/yy h:mmt"; DateTime.ParseExact(input, format, null); What am I doing wrong here? The following parse works ok.
3
2223
by: news.microsoft.com | last post by:
dim d as datetime d = DateTime.Parse(#6/10/2004 11:50:40 PM#) produces exception "String was not recognized as a valid DateTime." d = DateTime.Parse("6/10/2004 11:50:40 PM") is OK d = DateTime.Parse(#6/10/2004 11:50:40 AM#) is OK can somebody expain what is wrong with the first statement I am using VS 2003 with framework version 1.1 sp1 Thanx George
11
7258
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,...
1
4476
by: Pablo | last post by:
Hello, I have big problem with method ParseExact from class DateTime. Here is code sample: '----------------------------------------------------------------------------------------------------------------------------------------- Module Module1 Sub Main() Console.WriteLine("Start...") Try
1
51294
by: schouwla | last post by:
How do I use DateTime.Parse or DateTime.ParseExact to create a DateTime object from a string? I tried this without luck: string dateString = "27-02-2007"; // DateTime dt = DateTime.Parse(dateString); // Throws a FormatException exception IFormatProvider culture = new CultureInfo("fr-FR", true); DateTime dt = DateTime.ParseExact(dateString, "dd-mm-yyyy", culture); Console.WriteLine(dt);
3
3384
by: csharpula csharp | last post by:
Hello, I am trying to add DataTime.Now.ToString() to a file name but I get an exception while doing it that such format is not supported in path. How can I solve this and cast this issue? Thank you! *** Sent via Developersdex http://www.developersdex.com ***
0
9721
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
9601
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
10635
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10115
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...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
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
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.