none
DateTimePicker Returning incorrect value RRS feed

  • Question

  • I am porting code from VBA to a native .Net application using Visual Basic.  The code equivalent works properly in VBA.  

    A form employs a DateTimePicker.  When I try to extract the value of the date chosen, I get erroneous results.  I have searched online but can find no one that has addressed this issue.

    I initialize the field with

            DateTimePicker1.Format = DateTimePickerFormat.Custom
            DateTimePicker1.CustomFormat = "mm/dd/yyyy"
            DateTimePicker1.Value = Now.Date

    Later, I try to extract the date selected by the user

            Dim FRND as DateTime
            FRND = DateTimePicker1.Value

    What is returned is correct for the day and the year.  The month is always 00 (i.e., 00/03/2020)

    I would be grateful for some insight into how to correct this.

            


    • Edited by FlyinBlind Wednesday, January 8, 2020 2:22 PM editing mistype
    Wednesday, January 8, 2020 2:21 PM

Answers

  • Hi,

    You need to use "MM" for month (instead of "mm"), like this.
    DateTimePicker1.CustomFormat = "MM/dd/yyyy"

    Regards,

    Ashidacchi -- http://hokusosha.com

    • Marked as answer by FlyinBlind Tuesday, January 14, 2020 6:07 PM
    Friday, January 10, 2020 3:45 AM

All replies

  • Hi,

    You need to use "MM" for month (instead of "mm"), like this.
    DateTimePicker1.CustomFormat = "MM/dd/yyyy"

    Regards,

    Ashidacchi -- http://hokusosha.com

    • Marked as answer by FlyinBlind Tuesday, January 14, 2020 6:07 PM
    Friday, January 10, 2020 3:45 AM
  • Thank you Ashidacchi!  I appreciate your response
    Tuesday, January 14, 2020 6:07 PM