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. Getting midnight out of a calendar control

Getting midnight out of a calendar control

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

    Hi, I need to get a date out of a calendar control (set the CustomFormat to MM/dd/yy hh:mm tt), but when I call Convert.ToDateTime(dtpOrdStart.Value).ToString() I get the date and a random timestamp. Is there any way I can force it to 12:00:00 AM without having to go into the string and replace it myself? thanx

    C V J 3 Replies Last reply
    0
    • K kozu

      Hi, I need to get a date out of a calendar control (set the CustomFormat to MM/dd/yy hh:mm tt), but when I call Convert.ToDateTime(dtpOrdStart.Value).ToString() I get the date and a random timestamp. Is there any way I can force it to 12:00:00 AM without having to go into the string and replace it myself? thanx

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Set the time portion of the DateTime ?

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      V 1 Reply Last reply
      0
      • K kozu

        Hi, I need to get a date out of a calendar control (set the CustomFormat to MM/dd/yy hh:mm tt), but when I call Convert.ToDateTime(dtpOrdStart.Value).ToString() I get the date and a random timestamp. Is there any way I can force it to 12:00:00 AM without having to go into the string and replace it myself? thanx

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

        Sadly, it appears there is no way to directly do this. You can store the DateTime's Year, Month, and Day fields in temporary variables and construct a new DateTime object with these. Warning: I'm not sure, but using dt.AddHours(dt.Hours * (-1)) etc may cause problems with DST. The above method is, I think, the safest.

        Cheers, Vikram.


        "I will put my new found knolage to good use" - Captain See Sharp. "Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.

        1 Reply Last reply
        0
        • C Christian Graus

          Set the time portion of the DateTime ?

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

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

          Actually, you can't. The Hour property and others are read-only.

          Cheers, Vikram.


          "I will put my new found knolage to good use" - Captain See Sharp. "Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.

          1 Reply Last reply
          0
          • K kozu

            Hi, I need to get a date out of a calendar control (set the CustomFormat to MM/dd/yy hh:mm tt), but when I call Convert.ToDateTime(dtpOrdStart.Value).ToString() I get the date and a random timestamp. Is there any way I can force it to 12:00:00 AM without having to go into the string and replace it myself? thanx

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

            calendarControl.SelectedDate.Date the .Date property of a DateTime is midnight on that date.

            V 1 Reply Last reply
            0
            • J J4amieC

              calendarControl.SelectedDate.Date the .Date property of a DateTime is midnight on that date.

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

              Excellent, 5'd. Now how did I overlook that?

              Cheers, Vikram.


              "I will put my new found knolage to good use" - Captain See Sharp. "Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.

              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