Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DateTime format

DateTime format

Scheduled Pinned Locked Moved C#
databasesql-serversysadminhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goatstudio
    wrote on last edited by
    #1

    The Date in my sql server storedin US format, that is MM/DD/YYYY. I need to display the date in Asia format, or British format, that is DD/MM/YYYY. DateTimeFormatInfo Asian_DateTimeFormat = new CultureInfo("en-GB", false).DateTimeFormat; Console.WriteLine ("1. DateTime: 10/15/2004: " + System.DateTime.Parse ("10/15/2004", Asian_DateTimeFormat).ToShortDateString()); Above code give me an error. DateTimeFormatInfo Asian_DateTimeFormat = new CultureInfo("en-GB", false).DateTimeFormat; Console.WriteLine ("2. DateTime: 10/2/2004: " + System.DateTime.Parse ("10/2/2004", Asian_DateTimeFormat).ToShortDateString()); This code however successfully executed, and return me 2/10/2004. Wht can't the first code did the same? Any idea? Thanks! :D regards, vic

    D 1 Reply Last reply
    0
    • G goatstudio

      The Date in my sql server storedin US format, that is MM/DD/YYYY. I need to display the date in Asia format, or British format, that is DD/MM/YYYY. DateTimeFormatInfo Asian_DateTimeFormat = new CultureInfo("en-GB", false).DateTimeFormat; Console.WriteLine ("1. DateTime: 10/15/2004: " + System.DateTime.Parse ("10/15/2004", Asian_DateTimeFormat).ToShortDateString()); Above code give me an error. DateTimeFormatInfo Asian_DateTimeFormat = new CultureInfo("en-GB", false).DateTimeFormat; Console.WriteLine ("2. DateTime: 10/2/2004: " + System.DateTime.Parse ("10/2/2004", Asian_DateTimeFormat).ToShortDateString()); This code however successfully executed, and return me 2/10/2004. Wht can't the first code did the same? Any idea? Thanks! :D regards, vic

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Two reasons: 1) There are only 12 months in a year. 2) The second parameter in the Parse method is the format provider to use when parsing the date. By including the Asian culture in the Parse method, you told it that the date was in the form of DD/MM/YYYY, not MM/DD/YYYY. Since your parsing a US/English format date, you have to supply the Parse method the US/English culture. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      G 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Two reasons: 1) There are only 12 months in a year. 2) The second parameter in the Parse method is the format provider to use when parsing the date. By including the Asian culture in the Parse method, you told it that the date was in the form of DD/MM/YYYY, not MM/DD/YYYY. Since your parsing a US/English format date, you have to supply the Parse method the US/English culture. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        G Offline
        G Offline
        goatstudio
        wrote on last edited by
        #3

        Thanks Dave. :) I am now cracking my head to solve the problem. My server default date is US format, and the sql server as well. However, when users enter data through the web, they will enter 18/11/2004 (dd/mm/yyyy), I am trying to convert it and store in sql server using 11/18/2004 (mm/dd/yyyy). I wanted to do in dynamic way, hence I think globalization method in .Net is the solution. I try to parse by US format at first, then UK format... however end up still having error. How shall I deal with this? :sigh: Thanks! regards, vic

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups