Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating TextBox on Load with Date - 14 days -- HOW?

Status
Not open for further replies.

net123

Programmer
Oct 18, 2002
167
US
On Page_Load, I would like my web form to populate 1 textbox with a predefined date of today's date minus 14 days, i.e. 2 weeks ago.

I have the following so far:

Sub Page_Load(Src As Object, E As EventArgs)
If Not Page.IsPostBack Then
...
Dim dtmDate As DateTime = DateTime.Now
txtExceptionDate.Text = dtmDate.ToString("MM/dd/yyyy")
...
[/blue]
I have tried many, many combinations of trying to subtract 14 days from it but with no luck. I have tried other combinations as well. I posted the working code that simply displays today's date in the format I want it in, e.g. 10/27/2003

Your assistance would greatly be appreciated.
 
Hi,

Examining the System.DateTime class's, methods and properties reveals a method called AddDays(double) which returns "A System.DateTime whose value is the sum of the date and time represented by this instance and the number of days represented by value."

Code:
DateTime.Now.AddDays(-14)

:)

David
[pipe]
 
Another class to be at least aware of is the TimeSpan class, which allows a very flexible way to add, subtract, and otherwise tinker with DateTimes (based on many different units of measure).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top