Results 1 to 3 of 3

Thread: DateTimePicker Format help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Unhappy DateTimePicker Format help

    Hello,

    I need to have my date into a label.text = 03/10/2011

    I'm able to do that on my datetimepicker1 but when I try to pass to the text it brings in short date = 3/10/2011
    I need the zeros.

    Code:
    'format the datetimepicker value
            Me.DateTimePicker1.CustomFormat = "MM/dd/yyyy"
            Me.DateTimePicker1.Format = DateTimePickerFormat.Custom
    
            Me.Label1.Text = Me.DateTimePicker1.Value.ToShortDateString
    How can I have the value of label1.text with 03/10/2011 and not 3/10/2011?

    thanks,

    Kerb

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DateTimePicker Format help

    ToShortDateString uses the system short date format, so it's nothing to do with your DTP. If you want the same text as is in the DTP then just use the Text property of the DTP. Otherwise, call ToString and pass a custom format string instead of calling ToShortDateString.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Re: DateTimePicker Format help

    Thanks JMCilhinney,

    that was it,

    Me.Label1.Text = Me.DateTimePicker1.Value.ToString("MM/dd/yyyy")

    thanks,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width