DateTimePicker, display MMM-yy only-VBForums
Results 1 to 11 of 11

Thread: DateTimePicker, display MMM-yy only

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    51

    DateTimePicker, display MMM-yy only

    I want my DateTimePicker to display the Month and year only.

    So I have set the CustomFormat to MMM-yy.

    But in runtime when I change the month I get the following error

    "Year, Month, and Day parameters describe an un-representable DateTime."

    Is it possible to have the month and year only or do I need to include the day also??

  2. #2
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,448

    Re: DateTimePicker, display MMM-yy only

    How do you change the month in code?
    "Feel the force...read the source..."
    Utilities: POPFile • DebugView • Process Explorer • Wireshark • KeePass • UltraVNC • Pic2Ascii
    .Net tools & open source: DotNetNuke • log4Net • CLRProfiler
    My open source projects: Thales Simulator • EFT Calculator • System Info Reporter • VSS2SVN • IBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  3. #3
    Frenzied Member nmadd's Avatar
    Join Date
    Jun 2007
    Location
    Colorado, U.S.A.
    Posts
    1,676

    Re: DateTimePicker, display MMM-yy only

    You don't need to include the day:

    vb.net Code:
    1. Me.DateTimePicker1.Format = DateTimePickerFormat.Custom
    2. Me.DateTimePicker1.CustomFormat = "MMM-yy"

  4. #4

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    51

    Re: DateTimePicker, display MMM-yy only

    Hi thanks for the replies,

    I have set the custom format to "MMM-yy"

    But I get the error

    "Year, Month, and Day parameters describe an un-representable DateTime."

    If I change the format to "dd-MMM-yy" it works.

    ??

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,231

    Re: DateTimePicker, display MMM-yy only

    I'll tell you one thing that really does bother me: when people ask for help, then others ask questions to clarify the situation in order to answer that question and they get ignored. ntg asked a question:
    How do you change the month in code?
    Please answer it. I have tested your situation and I get no such error, so it must have something to do with how you're setting the date. Either you're just plain doing it wrong or it only applies to some specific date or dates. Either way, we need to know EXACTLY what you're doing when the error occurs, i.e. what code you're executing and what values your variables have at that point.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    51

    Re: DateTimePicker, display MMM-yy only

    Sorry, didn’t mean to offend anyone.

    Not sure what was meant by the question “How do you change the month in code”

    I am changing the month with the DateTimePicker.

    No code is being executed when I get the error.

    When the variable for the DateTimePicker is “” the date defaults to Jun-07. I have noticed I get the error when the month is changed and gets to “Jan”.

    If the DateTimePicker has a variable already saved to it eg “May-07” I don’t get the error when I change the date. It only seems to happen when the variable is “”.

  7. #7
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,448

    Re: DateTimePicker, display MMM-yy only

    If you're using a variable to assign a value to the datetimepicker, that's what I mean by "in code". Can you post the exact code you're using?
    "Feel the force...read the source..."
    Utilities: POPFile • DebugView • Process Explorer • Wireshark • KeePass • UltraVNC • Pic2Ascii
    .Net tools & open source: DotNetNuke • log4Net • CLRProfiler
    My open source projects: Thales Simulator • EFT Calculator • System Info Reporter • VSS2SVN • IBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  8. #8

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    51

    Re: DateTimePicker, display MMM-yy only

    The Variables for the DatetimePickers are "" until the DateTimePicker is set and saved for the first time.

    If the variable is saved as "Jan-00" I will get the error or when the DateTimePicker is adjusted when the variable is "".

    vb.net Code:
    1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    2.         Dim y As Integer = 0
    3.  
    4.         Me.ComboBox2.Text = Nothing
    5.         Me.ComboBox3.Text = Nothing
    6.         Me.ComboBox4.Text = Nothing
    7.         Me.ComboBox5.Text = Nothing
    8.         Me.ComboBox6.Text = Nothing
    9.        
    10.         For i As Integer = 0 To IbIDList.Count - 1
    11.             y = i
    12.             If IbSymbolList(i) = Me.ComboBox1.SelectedItem Then
    13.                 i = IbIDList.Count - 1
    14.             End If
    15.         Next i
    16.  
    17.         Me.ComboBox2.SelectedItem = IbExchList(y)
    18.         Me.ComboBox3.SelectedItem = SecTypeList(y)
    19.         Me.ComboBox4.SelectedItem = TimeZoneList(y)
    20.         Me.ComboBox5.SelectedItem = ShowList(y)
    21.         Me.ComboBox6.SelectedItem = CurrencyList(y)
    22.  
    23.         Me.DateTimePicker1.Text = SpotMonthList(y)
    24.         Me.DateTimePicker2.Text = NextExpList(y)
    25.         Me.DateTimePicker3.Text = LTDSpotMonthList(y)
    26.         Me.DateTimePicker4.Text = LTDNextExpList(y)
    27.  
    28.         Me.DateTimePicker5.Text = DayOpenTimeList(y)
    29.         Me.DateTimePicker6.Text = DayMocExitTimeList(y)
    30.  
    31.         Me.btSave.Enabled = False
    32.  
    33.     End Sub

  9. #9
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,448

    Re: DateTimePicker, display MMM-yy only

    I'm having trouble understanding what "the variable" is referring to. The listing you've provided doesn't really help since there are several calls to methods with bodies that aren't included.
    "Feel the force...read the source..."
    Utilities: POPFile • DebugView • Process Explorer • Wireshark • KeePass • UltraVNC • Pic2Ascii
    .Net tools & open source: DotNetNuke • log4Net • CLRProfiler
    My open source projects: Thales Simulator • EFT Calculator • System Info Reporter • VSS2SVN • IBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  10. #10
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,231

    Re: DateTimePicker, display MMM-yy only

    The simple fact is that you should NEVER be setting the Text property of a DateTimePicker control. You should be assigning a Date object to the Value property of the DateTimePicker and then the control does the formatting for you.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    51

    Re: DateTimePicker, display MMM-yy only

    I have set the format to MMM-yyyy and no longer get the error.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.