Date Format pb

F

Franck

Hi,
Got a pb with american date format MM/dd/YYYY.
My WebService Method convert String to Date.
It works good except for one case : 1/5/2005

Even if I set my regional settings to American, my WebService
understand this date as 1th of May and not %th of january.

I even try to change current thread culture in Application.BeginRequest
but did not work too.

Dim cult As System.Globalization.CultureInfo =
System.Globalization.CultureInfo.CreateSpecificCulture("en-GB")
cult.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"
System.Threading.Thread.CurrentThread.CurrentCulture = cult
System.Threading.Thread.CurrentThread.CurrentUICulture = cult

Help please !
My only goal is to convert every kind of date to yyyy-mm-dd...
If someone got a universal function to share with me, I'll thank him a
lot.
 
K

Katy King

Hi Franck,

Try either DateTime.ParseExact("1/5/2005", "M/d/yyyy");
or DateTime.Parse("1/5/2005", new CultureInfo("en-US"));

Then you can write the dates out again with DateTime.ToString("yyyy-MM-dd");

Katy


From: "Franck" <[email protected]>
|
| Hi,
| Got a pb with american date format MM/dd/YYYY.
| My WebService Method convert String to Date.
| It works good except for one case : 1/5/2005
|
| Even if I set my regional settings to American, my WebService
| understand this date as 1th of May and not %th of january.
|
| I even try to change current thread culture in Application.BeginRequest
| but did not work too.
|
| Dim cult As System.Globalization.CultureInfo =
| System.Globalization.CultureInfo.CreateSpecificCulture("en-GB")
| cult.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"
| System.Threading.Thread.CurrentThread.CurrentCulture = cult
| System.Threading.Thread.CurrentThread.CurrentUICulture = cult
|
| Help please !
| My only goal is to convert every kind of date to yyyy-mm-dd...
| If someone got a universal function to share with me, I'll thank him a
| lot.
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top