954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Show DateTime in Form box

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

EvilLinux
Junior Poster in Training
77 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 
currentTextBox.Text = DateTime.Today.ToShortDateString();
threeDaysTextBox.Text = DateTime.Today.Add(new TimeSpan(3, 0, 0, 0)).ToShortDateString();
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

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 useParse 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.

Antenka
Posting Whiz
362 posts since Nov 2008
Reputation Points: 293
Solved Threads: 82
 

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.

EvilLinux
Junior Poster in Training
77 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: