Results 1 to 3 of 3

Thread: [RESOLVED] [2.0] Date Range Auto Populated

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    Resolved [RESOLVED] [2.0] Date Range Auto Populated

    Hi guys,

    How can I auto populate these two text boxes with the date? Let us say Textbox1 will be automatically populated with the date 30 days earlier from the current date we have that can be found in TextBox2. To make it more clear:

    Code:
    Textbox1.Text = '12/13/2008'
    Textbox2.Text = '1/13/2009
    Those two text boxes are automatically populated under:

    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DateTime date = DateTime.Now();
                TextBox2.Text = date;
                DateTime earlydate = date - 30 days;
                TextBox1.Text = earlydate
            }
        }
    Thanks in advance

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

    Re: [2.0] Date Range Auto Populated

    First up, you probably want to use DateTime.Today rather than DateTime.Now, so that the time is zeroed. If you really do want the time then ignore that.

    As for the question, the DateTime structure has an AddDays method you can call, which accepts negative values too. There are similar methods for adding a number of minutes, years, etc.
    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
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    Re: [2.0] Date Range Auto Populated

    Thanks very much! It works great! More power to you jmcilhinney and God bless you!

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