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

Parsing custom datetime string

Hi,

I need to parse following string.
string dt = "Thur 11/2/2006 9:05:52 PM";

DateTime.Parse() or TryParse() fail to parse the given string. The day
in the above string "Thur" is causing the problem . If i change this
to "Thu" it gets parsed. Is there any way i can parse this string
without having to manually change "Thur" to "Thu".

Thanks
Sudeep.
Nov 2 '08 #1
2 2904
On Sun, 02 Nov 2008 09:05:35 +0100, Sudeep <su*******@gmail.comwrote:
Is there any way i can parse this string without having to manually
change "Thur" to "Thu".
You might be able to do this by implementing your own CultureInfo,
specifying all abbreviated names of week days (ddd) with four letter
strings, rather than the usual three letters strings provided by the
Engilsh cultures built into the framework.

However, it might just be a lot easier to simply remove the 4th char in
each date string as you recieve it :)

--
Joern Schou-Rode
http://malamute.dk/
Nov 2 '08 #2
Sudeep wrote:
I need to parse following string.
string dt = "Thur 11/2/2006 9:05:52 PM";

DateTime.Parse() or TryParse() fail to parse the given string. The day
in the above string "Thur" is causing the problem . If i change this
to "Thu" it gets parsed. Is there any way i can parse this string
without having to manually change "Thur" to "Thu".
Fix whatever is generating that non-standard format.

If that is not possible then:

string s = "Thur 11/02/2006 9:05:52 PM";
CultureInfo ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
DateTimeFormatInfo dtf = (DateTimeFormatInfo)ci.DateTimeFormat.Clone();
dtf.AbbreviatedDayNames = new string[] { "Sund", "Mond", "Tues", "Wedn",
"Thur", "Frid", "Satu" };
dtf.DateSeparator = "/";
dtf.TimeSeparator = ":";
dtf.AMDesignator = "AM";
dtf.PMDesignator = "PM";
ci.DateTimeFormat = dtf;
DateTime dt = DateTime.ParseExact(s, "ddd M/d/yyyy h:mm:ss tt", ci);

Arne
Nov 3 '08 #3

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

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
9
by: Thomas W | last post by:
I'm developing a web-application where the user sometimes has to enter dates in plain text, allthough a format may be provided to give clues. On the server side this piece of text has to be parsed...
2
by: Alan Gilmour | last post by:
Hi All, Does anyone know how to parse a custom datetime string. i.e. say I had a date time string in this format string thedate = "Tue, 5 AUG 2003 13:29:00" string theformat = "ddd, d mmm...
2
by: Sterling Ledet | last post by:
I am trying to create a web service that takes a string from my web server in the following format: Mon, 6 Oct 2003 18:39:47 UTC and put's in a datetime so it can then be reformatted in C# as...
50
by: z. f. | last post by:
HI, i have string in format dd/mm/yyyyy hh:mm:ss and giving this as an input to DateTime.Parse gives a string was not recognized as a valid date time format string error. how do i make the parse...
18
by: Atara | last post by:
In my apllication I use the following code: '-- My Code: Public Shared Function strDate2Date(ByVal strDate As String) As System.DateTime Dim isOk As Boolean = False If (strDate Is Nothing)...
5
by: Nikeman | last post by:
good day, I simply would like to know as to how I can parse seconds to convert them into equivalent DateTime representation. To be more persice, I have a DirectShow app written in VB.NET, with a...
8
by: a | last post by:
I'm trying to save data from a custom object into the profile object, but it is not structured the way that I want. I'm trying to get the custom object to serialize as xml to a Profile object...
5
by: Steven Berkovitz | last post by:
I am trying (without any luck) to find a way to parse a string and output its processed results. ie: string text = "This is text from a CMS tool <asp:Label runat=\"server\" id=\"test\"...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.