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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. date problem? help please ...

date problem? help please ...

Scheduled Pinned Locked Moved C#
helpquestioncsharpdatabasetutorial
4 Posts 3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    hi all, how can i process date info and insert into database (into a date/time field) without any difficulty ? i mean there are some differences between date format in different countries. (for example: english > MM/dd/yyyy or turkish > dd/MM/yyy) how can i first check the language info used by the computer then process date according to that with c# ? help please ...

    E 1 Reply Last reply
    0
    • L Lost User

      hi all, how can i process date info and insert into database (into a date/time field) without any difficulty ? i mean there are some differences between date format in different countries. (for example: english > MM/dd/yyyy or turkish > dd/MM/yyy) how can i first check the language info used by the computer then process date according to that with c# ? help please ...

      E Offline
      E Offline
      Empires
      wrote on last edited by
      #2

      You could use a CultureInfo instance for formatting as shown below: DateTime dt = DateTime.Parse("08/01/2006"); // Use the machines current culture. Console.WriteLine("Current Culture: {0}.", dt.ToString(CultureInfo.CurrentCulture)); // If you want to use another culture without switching your current culture you could try. Console.WriteLine("English (US) Formatted Date: {0}.", dt.ToString(new CultureInfo("en-US"))); Console.WriteLine("English (GB) Formatted Date: {0}.", dt.ToString(new CultureInfo("en-GB"))); // Output English (US) Formatted Date: 8/1/2006 12:00:00 AM. English (GB) Formatted Date: 01/08/2006 00:00:00.

      L 1 Reply Last reply
      0
      • E Empires

        You could use a CultureInfo instance for formatting as shown below: DateTime dt = DateTime.Parse("08/01/2006"); // Use the machines current culture. Console.WriteLine("Current Culture: {0}.", dt.ToString(CultureInfo.CurrentCulture)); // If you want to use another culture without switching your current culture you could try. Console.WriteLine("English (US) Formatted Date: {0}.", dt.ToString(new CultureInfo("en-US"))); Console.WriteLine("English (GB) Formatted Date: {0}.", dt.ToString(new CultureInfo("en-GB"))); // Output English (US) Formatted Date: 8/1/2006 12:00:00 AM. English (GB) Formatted Date: 01/08/2006 00:00:00.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        hi again, cool and thanks for your reply. but i just need English (US) Formatted Date: 8/1/2006 this part. the rest should be omitted. Console.WriteLine("English (US) Formatted Date: {0}.", dt.ToShortDateString(new CultureInfo("en-US"))); doesnt work :( what else can i do ?

        S 1 Reply Last reply
        0
        • L Lost User

          hi again, cool and thanks for your reply. but i just need English (US) Formatted Date: 8/1/2006 this part. the rest should be omitted. Console.WriteLine("English (US) Formatted Date: {0}.", dt.ToShortDateString(new CultureInfo("en-US"))); doesnt work :( what else can i do ?

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          This should do the trick:

          Console.WriteLine("English (US) Formatted Date: {0}.", dt.ToString("d", new CultureInfo("en-US")));


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          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