Hi real quick one and most likely going to look stupid after this.

I need to show the Current Date in a form text box. Also the second textbox I have needs to show the date + 3 (show the date 3 days later). For some reason I can't figure out the string to get these to post so far I got:

//Current Date when form opens
DateTime arrivaldate = DateTime.Now;
//Add 3 days to departuredate
DateTime departuredate = DateTime.Parse("DateTime.Now");
DateTime adddays = departuredate.AddDays(3);

arrivalTxb =
departureTxb =

arrivalTxb is the first text box, and departureTxb is the second text box.

The other part I have to valid to make sure the departure date doesn't go past 5 years, but thats something I think I can figure out.

Thanks in advance

7 Years
Discussion Span
Last Post by EvilLinux
currentTextBox.Text = DateTime.Today.ToShortDateString();
threeDaysTextBox.Text = DateTime.Today.Add(new TimeSpan(3, 0, 0, 0)).ToShortDateString();

Hello, EvilLinux.
At first - you should post your code in code tags.
About your code:
this should take current date and time

DateTime arrivaldate = DateTime.Now;

then troubles comes from here:

DateTime departuredate = DateTime.Parse("DateTime.Now");

to use Parse method with 1 string parameter, you should use something like this:

DateTime someDate = DateTime.Parse("15.09.09");

now about this one:

DateTime adddays = departuredate.AddDays(3);

Adds the specified number of days to the value of this instance.
Return Value
Type: System.DateTime
A DateTime whose value is the sum of the date and time represented by this instance and the number of days represented by value.

so, the result of AddDays is your departuredate.

Also to convert this date to string you can use either ToLongDateString(); or .ToLongTimeString(); methods.


I feel really really stupid, because when I was playing with it again, I walked away for a bit, and then remember that I was working in the btnclick field... I.E. reason why I couldn't get the dates to come and then moved them to the correct field and bam they worked. And yeah sorry forgot the add code tags I'll fix that.

Thanks again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.