|
-
Jan 13th, 2009, 01:17 AM
#1
Thread Starter
Addicted Member
[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
-
Jan 13th, 2009, 01:23 AM
#2
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.
-
Jan 13th, 2009, 01:47 AM
#3
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|