SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    uk
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    converting date from uk to us

    hi

    this should be easy but cant get a solution to work, tried changing localte to us and using datetime.parse (mm/dd/yyyy) but no joy...

    im accepting a date in a textbox as dd/mm/yyyy

    unfortunately the server locale is set to US so a date such as 23/04/2008 causes it to error as its thinking 23 is the month.

    i need to swap the dd and mm round before adding to db.

    whats the way to do this?

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    uk
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    forgot to add im using C#

  3. #3
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,878
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    date.ToString("MM/dd/yyyy");

    That could help you out. I formats the date string in that format

  4. #4
    SitePoint Evangelist praetor's Avatar
    Join Date
    Aug 2005
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about changing your UI culture to en-GB ?

  5. #5
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a method that accepts to parameters:
    Code Csharp:
    DateTime.Parse (string s, IFormatProvider provider)
    The second parameter supplies culture-specific format information about date format.

    Examples:
    Code Csharp:
    DateTime.Parse ("04/23/2008", new CultureInfo("en-US"));
    DateTime.Parse ("23/04/2008", new CultureInfo("fr-FR"));


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •