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. string to datetime conversion ?

string to datetime conversion ?

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 4 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.
  • A Offline
    A Offline
    Aghosh Babu
    wrote on last edited by
    #1

    hi all, i have a string string date= "09/02/27, 12:23:04" the above string is in yy/mm/dd format, i want to convert it into a DateTime variable. When i convert i am getting the output as 9/2/2027, 12:23:04 PM which is wrong. I have tried the below code: DateTime dt = Convert.ToDateTime(date); so i suspect its not the way, i think there are something to do with the Globalization namespace? any help will be much apreciated.....thanks..........:rose:

    S V 2 Replies Last reply
    0
    • A Aghosh Babu

      hi all, i have a string string date= "09/02/27, 12:23:04" the above string is in yy/mm/dd format, i want to convert it into a DateTime variable. When i convert i am getting the output as 9/2/2027, 12:23:04 PM which is wrong. I have tried the below code: DateTime dt = Convert.ToDateTime(date); so i suspect its not the way, i think there are something to do with the Globalization namespace? any help will be much apreciated.....thanks..........:rose:

      S Offline
      S Offline
      Shyam K Pananghat
      wrote on last edited by
      #2

      Yes.. Datetime objects acts according to your globalisation settings in yout machine/Application. The easiest way is to use Datetime.Tostring(yy/mm/dd) whenever you want ot display it :-D

      Shyam.. My Blog dotnetscoups.blogspot.com

      1 Reply Last reply
      0
      • A Aghosh Babu

        hi all, i have a string string date= "09/02/27, 12:23:04" the above string is in yy/mm/dd format, i want to convert it into a DateTime variable. When i convert i am getting the output as 9/2/2027, 12:23:04 PM which is wrong. I have tried the below code: DateTime dt = Convert.ToDateTime(date); so i suspect its not the way, i think there are something to do with the Globalization namespace? any help will be much apreciated.....thanks..........:rose:

        V Offline
        V Offline
        Vikram A Punathambekar
        wrote on last edited by
        #3

        DateTime.ParseExact() is what you need.

        Cheers, Vıkram.


        I've never ever worked anywhere where there has not been someone who given the choice I would not work with again. It's a job, you do your work, put up with the people you don't like, accept there are probably people there that don't like you a lot, and look forward to the weekends.   - Josh Gray.

        A 1 Reply Last reply
        0
        • V Vikram A Punathambekar

          DateTime.ParseExact() is what you need.

          Cheers, Vıkram.


          I've never ever worked anywhere where there has not been someone who given the choice I would not work with again. It's a job, you do your work, put up with the people you don't like, accept there are probably people there that don't like you a lot, and look forward to the weekends.   - Josh Gray.

          A Offline
          A Offline
          Aghosh Babu
          wrote on last edited by
          #4

          i will be gratefull if u can provide me a sample code, what are the values inside parseExact()??

          J 1 Reply Last reply
          0
          • A Aghosh Babu

            i will be gratefull if u can provide me a sample code, what are the values inside parseExact()??

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            Gosh, those buggers at Microsoft have been hiding that in the documentation[^] again havent they.

            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