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

Home Posts Topics Members FAQ

DateTime.ParseE xact problem with parsing "8/09/05 9:27a"

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.ParseE xact(input, format, null);

What am I doing wrong here? The following parse works ok.

string input = "9-08-05 9:27";
string format = "d-MM-yy H:mm";

Nov 17 '05 #1
5 1749
The follow *should* work for you but I'm not sure how it handles
globalization as I'm doing this from memory.

===============
using System.Globaliz ation;
....
....
DateTimeFormatI nfo formatInfo = new DateTimeFormatI nfo();
formatInfo.AMDe signator = "am";

string input = "8/09/05 9:27a";
string format = "M/dd/yy h:mmt";
DateTime.ParseE xact(input, format, formatInfo)
===============

Hope this helps.

Brian Delahunty
Ireland

http://briandela.com/blog
"ra*********@gm ail.com" wrote:
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.ParseE xact(input, format, null);

What am I doing wrong here? The following parse works ok.

string input = "9-08-05 9:27";
string format = "d-MM-yy H:mm";

Nov 17 '05 #2
> string input = "8/09/05 9:27a";
string format = "M/dd/yy h:mmt";
DateTime.ParseE xact(input, format, null);

The "t" format specifier expects a capital A. The following input parses
fine:

string input = "8/09/05 9:27A";

Gretings,
Wessel
Nov 17 '05 #3
Thanks that did the trick!

Nov 17 '05 #4
Capitilizing didn't help. I needed to add a DateTimeFormatI nfo where I
specified the AM/PMDesignator. The anwser of Brian Delahunty works.

Nov 17 '05 #5
No Problem. Glad I could help.

--
Brian Delahunty
Ireland

http://briandela.com/blog
"Ramon Smits aka Exyll" wrote:
Thanks that did the trick!

Nov 17 '05 #6

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

Similar topics

0
1605
by: Fred Strauss | last post by:
I am having an odd problem using the DateTime.ParseExact() method that I'm hoping someone can help me with. I have XML files that use 2 different date formats internally. I am trying to use the same call to ParseExact to parse either format. I am using C# to call the following form of ParseExact: public static DateTime ParseExact(string, string, IFormatProvider, DateTimeStyles);
3
7792
by: Dave P. | last post by:
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.Globalization.CultureInfo ("en-US"); DateTime dt = DateTime.ParseExact("Mar 9, 2005", "MMM d, yyyy", fp);
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
15037
by: Erica | last post by:
Hi. I have a string: "11/24/2006 23:59" named StartDateTime I need the string to be converted into a DateTime object in the following format: 2006-11-24 11:59 PM I tried the following: DateTime.ParseExact(StartDateTime,"yyyy-MM-dd HH:mm tt*", System.Globalization.CultureInfo.CurrentCulture)
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
21278
by: Peter Duniho | last post by:
I'm sure there's a good explanation for this, but I can't figure it out. I tried using DateTime.Parse() with a custom DateTimeFormatInfo instance, in which I'd replaced the DateTimeFormatInfo.FullDateTimePattern property with my custom format string: DateTimeFormatInfo dtfi = (DateTimeFormatInfo)DateTimeFormatInfo.InvariantCulture.Clone(); dtfi.FullDateTimePattern = "dd/MMM/yyyy:HH:mm:ss zzz";
11
9846
by: Peter Holschbach | last post by:
Hi, I've the following line of code: result = DateTime.ParseExact("1999-12-01T23:59:59Z", "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture); where I get in result "result" "02.12.1999 00:59:59" instead of teh expected "01.12.1999 23:59:59" Anybody a idea ?
5
5613
by: John B | last post by:
Hi all, Any idea why this code results in a FormatException? DateTime.ParseExact("40708", "dMMyy", CultureInfo.CurrentCulture) If I use "040708" with the same format string it works and it parses all double digit days fine. TIA JB
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
10376
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...
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...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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
5550
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
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.