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. Convert.ToDateTime Problem

Convert.ToDateTime Problem

Scheduled Pinned Locked Moved C#
helptutorial
6 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.
  • S Offline
    S Offline
    Support123
    wrote on last edited by
    #1

    Hi all, Yesterday i had the problem when i tried to convert a string to DateTime I wanted to do the following: string _appDate=_CurrentSelectedDate.Date.ToString("yyyy/MM/dd"); string _fromDateTime = _appDate+" "+startTime; string _endDateTime = _appDate+" "+endTime; FromTime = Convert.ToDateTime(_fromDateTime); ToTime = Convert.ToDateTime(_endDateTime); Now in this example the value of _appDate is "2006/11/07" the value of _startTime is "4:00 PM" the value of _endTime is "5:00 PM" That makes the value of _fromDateTime = "2006/11/07 4:00 PM" and the value of _endDateTime = "2006/11/07 5:00 PM" I checked and it is... Now when i try to Convert.ToDateTime for the FromDate and the ToDate The value of FromTime is 7/11/2006 and value of ToTime is 7/11/2006 :confused: on the other computer the values are correct but not on mine... The regional settings are the same... Please help

    "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

    _ L 2 Replies Last reply
    0
    • S Support123

      Hi all, Yesterday i had the problem when i tried to convert a string to DateTime I wanted to do the following: string _appDate=_CurrentSelectedDate.Date.ToString("yyyy/MM/dd"); string _fromDateTime = _appDate+" "+startTime; string _endDateTime = _appDate+" "+endTime; FromTime = Convert.ToDateTime(_fromDateTime); ToTime = Convert.ToDateTime(_endDateTime); Now in this example the value of _appDate is "2006/11/07" the value of _startTime is "4:00 PM" the value of _endTime is "5:00 PM" That makes the value of _fromDateTime = "2006/11/07 4:00 PM" and the value of _endDateTime = "2006/11/07 5:00 PM" I checked and it is... Now when i try to Convert.ToDateTime for the FromDate and the ToDate The value of FromTime is 7/11/2006 and value of ToTime is 7/11/2006 :confused: on the other computer the values are correct but not on mine... The regional settings are the same... Please help

      "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

      _ Offline
      _ Offline
      _mubashir
      wrote on last edited by
      #2

      What exactly is the problem? Arent you getting the time values? Mubashir

      Every job is a self portrait of the person who did it.

      S 3 Replies Last reply
      0
      • _ _mubashir

        What exactly is the problem? Arent you getting the time values? Mubashir

        Every job is a self portrait of the person who did it.

        S Offline
        S Offline
        Support123
        wrote on last edited by
        #3

        Oh no sorry... I only get the date back like this... "11/7/2006" I want it to work like it does on the other PC "2006/07/11 4:00:00 PM" It worked on my PC too but i haven't changed the regional settings, i haven't altered the code of this segment...only now to try and fix it. I don't know... :((

        "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

        1 Reply Last reply
        0
        • _ _mubashir

          What exactly is the problem? Arent you getting the time values? Mubashir

          Every job is a self portrait of the person who did it.

          S Offline
          S Offline
          Support123
          wrote on last edited by
          #4

          Hi, This problem has a whole new twist.... Everywhere in my code where i use the Covert.ToDateTime i have the same problem... it doesn't show me the time any more... only the date but not even in the yyyy/MM/dd format, now it is in the dd/MM/yyyy format. Do you think that if i built the installer and and installed it onto another computer that it would work... I mean there is nothing wrong with the code, it's just weird... i checked the regional settings again => same as the other computer... before i build the installer, and find a pc to install it on... do you think it would work correctly on another PC if it's acting weird on mine?

          "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

          1 Reply Last reply
          0
          • _ _mubashir

            What exactly is the problem? Arent you getting the time values? Mubashir

            Every job is a self portrait of the person who did it.

            S Offline
            S Offline
            Support123
            wrote on last edited by
            #5

            Ha, it works.... there must be something wrong on my pc... some setting or something... Thank you for your time... I think i need to reinstall my PC. :doh: But, this at least will speed up my system a little... :-)

            "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

            1 Reply Last reply
            0
            • S Support123

              Hi all, Yesterday i had the problem when i tried to convert a string to DateTime I wanted to do the following: string _appDate=_CurrentSelectedDate.Date.ToString("yyyy/MM/dd"); string _fromDateTime = _appDate+" "+startTime; string _endDateTime = _appDate+" "+endTime; FromTime = Convert.ToDateTime(_fromDateTime); ToTime = Convert.ToDateTime(_endDateTime); Now in this example the value of _appDate is "2006/11/07" the value of _startTime is "4:00 PM" the value of _endTime is "5:00 PM" That makes the value of _fromDateTime = "2006/11/07 4:00 PM" and the value of _endDateTime = "2006/11/07 5:00 PM" I checked and it is... Now when i try to Convert.ToDateTime for the FromDate and the ToDate The value of FromTime is 7/11/2006 and value of ToTime is 7/11/2006 :confused: on the other computer the values are correct but not on mine... The regional settings are the same... Please help

              "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

              L Offline
              L Offline
              lainoo
              wrote on last edited by
              #6

              i have this question, but i use two datetimepicker later: dt1 =DateTime .Parse(dateTimePicker11.Value.ToLongDateString()+" "+dateTimePicker12.Value.ToLongTimeString()); it is right.

              Sorry ...

              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