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. Help on Copy/Paste for DateTimePicker

Help on Copy/Paste for DateTimePicker

Scheduled Pinned Locked Moved C#
questiondesigncollaborationhelptutorial
12 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.
  • M Offline
    M Offline
    manju 3
    wrote on last edited by
    #1

    Hi Team, Need your help on Copy/Paste on DateTimePicker. I am displaying the UI in DD/MM/YY format and when I copy it copies in the same format(DD/MM/YY). But Paste uses MM/DD/YY format. How can i change the Paste format to DD/MM/YY? Example UI is displaying 16/02/18(which is todays date in DD/MM/YY) and when I copy it copies as it is 16/12/18. Now I modify it as tomorrows date 17/12/18 I does not allow as it validates for MM/DD/YY and 17 is greater then 12 so it does not copy. How can i change the format to DD/MM/YY before pasting? Thanks Sharan

    OriginalGriffO Richard DeemingR L 3 Replies Last reply
    0
    • M manju 3

      Hi Team, Need your help on Copy/Paste on DateTimePicker. I am displaying the UI in DD/MM/YY format and when I copy it copies in the same format(DD/MM/YY). But Paste uses MM/DD/YY format. How can i change the Paste format to DD/MM/YY? Example UI is displaying 16/02/18(which is todays date in DD/MM/YY) and when I copy it copies as it is 16/12/18. Now I modify it as tomorrows date 17/12/18 I does not allow as it validates for MM/DD/YY and 17 is greater then 12 so it does not copy. How can i change the format to DD/MM/YY before pasting? Thanks Sharan

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      How are you copying? How are you pasting? Show the relevant code fragments!

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      M 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        How are you copying? How are you pasting? Show the relevant code fragments!

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        M Offline
        M Offline
        manju 3
        wrote on last edited by
        #3

        I have not added any code specific for copy paste. I have just changed the property of DateTimePicker is.dateTimePicker.CustomFormat = "dd/MM/yy HH:mm:ss"; is.dateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; is.dateTimePickerExecTime.ShowUpDown = true; Once right click on Control I select on Copy it copies and I copy it in excel . From excel I again copy and trying to paste it on control.

        OriginalGriffO 1 Reply Last reply
        0
        • M manju 3

          I have not added any code specific for copy paste. I have just changed the property of DateTimePicker is.dateTimePicker.CustomFormat = "dd/MM/yy HH:mm:ss"; is.dateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; is.dateTimePickerExecTime.ShowUpDown = true; Once right click on Control I select on Copy it copies and I copy it in excel . From excel I again copy and trying to paste it on control.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Well what did you expect to happen? You copy a date in a non-standard form, paste it into a spreadsheet (which identifies it as a date and converts it to a DateTime object), then you copy that datetime object from Excel (in standard-for-that-PC format), and paste it back onto a control that doesn't expect standard format. There isn't a whole lot that we can do to prevent that causing a problem! :laugh:

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          M 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Well what did you expect to happen? You copy a date in a non-standard form, paste it into a spreadsheet (which identifies it as a date and converts it to a DateTime object), then you copy that datetime object from Excel (in standard-for-that-PC format), and paste it back onto a control that doesn't expect standard format. There isn't a whole lot that we can do to prevent that causing a problem! :laugh:

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

            M Offline
            M Offline
            manju 3
            wrote on last edited by
            #5

            Yes. Copy in DD/MM/YY format and paste the same in spreadsheet. Edit the DateTime in spreadsheet. Copy from spreadsheet and paste back to the DateTime control. But DateTime control allows MM/DD/YY format. That's the issue :(

            OriginalGriffO 1 Reply Last reply
            0
            • M manju 3

              Yes. Copy in DD/MM/YY format and paste the same in spreadsheet. Edit the DateTime in spreadsheet. Copy from spreadsheet and paste back to the DateTime control. But DateTime control allows MM/DD/YY format. That's the issue :(

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              And I'm confused about what you think we can do about a user input problem like that!

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • M manju 3

                Hi Team, Need your help on Copy/Paste on DateTimePicker. I am displaying the UI in DD/MM/YY format and when I copy it copies in the same format(DD/MM/YY). But Paste uses MM/DD/YY format. How can i change the Paste format to DD/MM/YY? Example UI is displaying 16/02/18(which is todays date in DD/MM/YY) and when I copy it copies as it is 16/12/18. Now I modify it as tomorrows date 17/12/18 I does not allow as it validates for MM/DD/YY and 17 is greater then 12 so it does not copy. How can i change the format to DD/MM/YY before pasting? Thanks Sharan

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                A simple solution: display your UI to your users using their preferring culture settings. We're all quick to complain when Microsoft products ignore our settings and display dates in US format; so why should our applications be exempt? For extra points, use an unambiguous format like dd-MMM-yyyy. Standard Date and Time Format Strings | Microsoft Docs[^] Custom Date and Time Format Strings | Microsoft Docs[^]


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                1 Reply Last reply
                0
                • M manju 3

                  Hi Team, Need your help on Copy/Paste on DateTimePicker. I am displaying the UI in DD/MM/YY format and when I copy it copies in the same format(DD/MM/YY). But Paste uses MM/DD/YY format. How can i change the Paste format to DD/MM/YY? Example UI is displaying 16/02/18(which is todays date in DD/MM/YY) and when I copy it copies as it is 16/12/18. Now I modify it as tomorrows date 17/12/18 I does not allow as it validates for MM/DD/YY and 17 is greater then 12 so it does not copy. How can i change the format to DD/MM/YY before pasting? Thanks Sharan

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

                  Your idea of "paste" may not correspond to the reality of the situation. Sometimes you can use "windows paste commands"; at other times, you need to interect with the "clip board", reformat, copy (not "paste") to a property of the TextBox; etc. i.e. "programming".

                  "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                  M 2 Replies Last reply
                  0
                  • L Lost User

                    Your idea of "paste" may not correspond to the reality of the situation. Sometimes you can use "windows paste commands"; at other times, you need to interect with the "clip board", reformat, copy (not "paste") to a property of the TextBox; etc. i.e. "programming".

                    "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                    M Offline
                    M Offline
                    manju 3
                    wrote on last edited by
                    #9

                    Thanks for all your responses Is there a way where I can change the .MaxValue Property? Presently it displays in MM/DD/YYYY(12/31/9999 11:59 PM). Can I set it to DD/MM/YYYY(31/12/1999).

                    1 Reply Last reply
                    0
                    • L Lost User

                      Your idea of "paste" may not correspond to the reality of the situation. Sometimes you can use "windows paste commands"; at other times, you need to interect with the "clip board", reformat, copy (not "paste") to a property of the TextBox; etc. i.e. "programming".

                      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                      M Offline
                      M Offline
                      manju 3
                      wrote on last edited by
                      #10

                      Do we have any event for Paste where I can trigger and reformat the Date and paste it in the control ?

                      L 1 Reply Last reply
                      0
                      • M manju 3

                        Do we have any event for Paste where I can trigger and reformat the Date and paste it in the control ?

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

                        You didn't specify WPF, Windows Forms or ASP.NET or ... If you're going to use a "date picker", you need to "learn it" before "looking around" for "other" solutions. This may help; also note the reference to "system settings". [c# - Getting date from DatePicker in format yyyy/MM/dd - Stack Overflow](https://stackoverflow.com/questions/14002425/getting-date-from-datepicker-in-format-yyyy-mm-dd)

                        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                        M 1 Reply Last reply
                        0
                        • L Lost User

                          You didn't specify WPF, Windows Forms or ASP.NET or ... If you're going to use a "date picker", you need to "learn it" before "looking around" for "other" solutions. This may help; also note the reference to "system settings". [c# - Getting date from DatePicker in format yyyy/MM/dd - Stack Overflow](https://stackoverflow.com/questions/14002425/getting-date-from-datepicker-in-format-yyyy-mm-dd)

                          "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                          M Offline
                          M Offline
                          manju 3
                          wrote on last edited by
                          #12

                          Thank you for your suggestions. I have achieved it using ParseExact function with some formatting the DateTime value. Thanks Sharan

                          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