Date Format pb

Discussion in 'ASP .Net Web Services' started by Franck, Apr 21, 2005.

  1. Franck

    Franck Guest

    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.
     
    Franck, Apr 21, 2005
    #1
    1. Advertising

  2. Franck

    Katy King Guest

    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" <>
    |
    | 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.
    |
    |
     
    Katy King, Apr 21, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,207
    Janaka
    Feb 18, 2004
  2. DC
    Replies:
    5
    Views:
    3,035
    Brendan Reynolds
    Jul 1, 2005
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,374
    Michael Borgwardt
    May 30, 2004
  4. Chu
    Replies:
    3
    Views:
    4,238
    Shawn
    Aug 15, 2006
  5. Josh Sharpe
    Replies:
    1
    Views:
    228
    Brian Candler
    Sep 21, 2010
Loading...

Share This Page