469,578 Members | 1,775 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

Date format problem

Hi,

I'm trying to convert a string to date by specifying the format. The value
is like this: "03rd of April 2006". Now this is converted fine by using the
following format: "dd\r\d \o\f MMMM yyyy". The problem is of course that the
string can be 01st of..., 04th of etc., meaning that I can't use the "\r\d"
format description for all possible values.

Any suggestions? Is there a wildcard i can use, like "dd\?\?"...

Thanks,

Zsolt
Mar 8 '06 #1
1 1530
Hello,

If you know all the possible formats you can do something like this.

string[] expectedFormats = {"dd\r\d \o\f MMMM yyyy", "dd\s\t \o\f MMMM
yyyy", "dd\t\h \o\f MMMM yyyy"};
DateTime validDateTime = Response.Write(DateTime.ParseExact("03rd of
April 2006", expectedFormats,
System.Globalization.CultureInfo.CurrentUICulture,
System.Globalization.DateTimeStyles.AllowWhiteSpac es));

--------------------
From: "zsolt" <no@mail.com>
Subject: Date format problem
Date: Wed, 8 Mar 2006 19:16:44 +0100
Lines: 21
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Message-ID: <#z**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: mail.itfi.no 194.248.208.94
Path: TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:190426
X-Tomcat-NG: microsoft.public.dotnet.general

Hi,

I'm trying to convert a string to date by specifying the format. The value
is like this: "03rd of April 2006". Now this is converted fine by using thefollowing format: "dd\r\d \o\f MMMM yyyy". The problem is of course that thestring can be 01st of..., 04th of etc., meaning that I can't use the "\r\d"format description for all possible values.

Any suggestions? Is there a wildcard i can use, like "dd\?\?"...

Thanks,

Zsolt


--

Thank You,
Nanda Lella,

This Posting is provided "AS IS" with no warranties, and confers no rights.

Mar 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Dario Di Bella | last post: by
12 posts views Thread by Assimalyst | last post: by
30 posts views Thread by fniles | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.