[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
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.
Re: [2.0] Date Range Auto Populated
Thanks very much! It works great! More power to you jmcilhinney and God bless you!