Is there a way to dynamically set the default value of a DateTimePicker control?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #1

    Is there a way to dynamically set the default value of a DateTimePicker control?

    Is there a way to dynamically set the default value of a DateTimePicker control.
    So at start-up the date displayed is yesterday's date or one month ago.
    Code:
    this.dtPickStart.Value = new System.DateTime(2010, 11, 22, 0, 0, 0, 0);
    Rather than a literal value as set in 'Properties'
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I'm not sure what you are having problems with.
    I did this in a Form Load event and it sets a DateTimePicker called DPTest to yesterday's date:

    (C#)
    Code:
    DateTime  yesterday = DateTime.Today.Subtract(new TimeSpan(1)).Date;
    DPTest.Value = yesterday;
    (VB.NET)
    Code:
    Dim yesterday As DateTime = DateTime.Today.Subtract(New TimeSpan(1)).Date
    DPTest.Value = yesterday
    -Frinny
    Last edited by Frinavale; Dec 7 '10, 02:05 PM.

    Comment

    Working...