473,399 Members | 2,774 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,399 software developers and data experts.

DateTime.ParseExact 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.ParseExact(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 1709
The follow *should* work for you but I'm not sure how it handles
globalization as I'm doing this from memory.

===============
using System.Globalization;
....
....
DateTimeFormatInfo formatInfo = new DateTimeFormatInfo();
formatInfo.AMDesignator = "am";

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

Hope this helps.

Brian Delahunty
Ireland

http://briandela.com/blog
"ra*********@gmail.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.ParseExact(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.ParseExact(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 DateTimeFormatInfo 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
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...
3
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()). ...
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...
1
by: Pablo | last post by:
Hello, I have big problem with method ParseExact from class DateTime. Here is code sample: ...
1
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:...
1
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 =...
3
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...
11
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...
5
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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...
0
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...
0
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...

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.