How add days based on current date

Posted by Rrana under ASP.NET on 9/6/2011 | Points: 10 | Views : 5197 | Status : [Member] | Replies : 3
Hi,

My problem is

=============
i want to get current date or user selected date, based on that date i want add 7 days

Ex:--

i dispaly today's date in txtdate(09/06/2011)

06 is date
09 is month

i want output lke this

09/06/2011
09/07/2011
09/08/2011
09/09/2011
09/10/2011
09/11/2011
09/12/2011

and i want to display dayof week also


======================== my code is---------------

DateTime txtDate = Convert.ToDateTime(DatePicker1.DateBox.Text);

string day = txtDate.DayOfWeek.ToString();

in txtdate i get the date like (09/06/2011)
but it assumes that 06 is month and 09 is day
so it dispaly thursday(09)


Thanks

Sucharitha Goud
Bank Of America..



Responses

Posted by: Niladri.biswas on: 9/7/2011 [Member] Platinum | Points: 25

Up
0
Down
Try this

 DateTime txtDate = Convert.ToDateTime(String.Format("{0:MM/dd/yyyy}", DatePicker1.DateBox.Text));


Thanks

Best Regards,
Niladri Biswas

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rrana on: 9/7/2011 [Member] Starter | Points: 25

Up
0
Down

Hi Niladri,

Thanks for response,

either it sysdate or user entered date by selecting calendar

and i want to display the 7 dates in 7 textboxes

Ex:-- If use enter 09/08/2011 by selecting calendar or system date

here 09 is month

08 is date

textbox1.text= 09/08/2011
textbox2.text= 09/09/2011
textbox3.text= 09/10/2011
textbox4.text= 09/11/2011
textbox5.text= 09/12/2011
textbox6.text= 09/13/2011
textbox7.text= 09/14/2011


08 is Thursday right ? so i want to display thursday(only 1st day) in another textbox

My code is ======================


DateTime txtDate = Convert.ToDateTime(DatePicker1.DateBox.Text );

Date1.Text = txtDate.AddDays(0).ToShortDateString();
Date2.Text = txtDate.AddDays(1).ToShortDateString();
Date3.Text = txtDate.AddDays(2).ToShortDateString();
Date4.Text = txtDate.AddDays(3).ToShortDateString();
Date5.Text = txtDate.AddDays(4).ToShortDateString();
Date6.Text = txtDate.AddDays(5).ToShortDateString();
Date7.Text = txtDate.AddDays(6).ToShortDateString();

But it adds the month not date

thanks in advance












Sucharitha Goud
Bank Of America..

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rrana on: 9/7/2011 [Member] Starter | Points: 25

Up
0
Down
DateTime txtDate = Convert.ToDateTime(DatePicker1.DateBox.Text );

Date1.Text = txtDate.AddDays(0).ToShortDateString();
Date2.Text = txtDate.AddDays(1).ToShortDateString();
Date3.Text = txtDate.AddDays(2).ToShortDateString();
Date4.Text = txtDate.AddDays(3).ToShortDateString();
Date5.Text = txtDate.AddDays(4).ToShortDateString();
Date6.Text = txtDate.AddDays(5).ToShortDateString();
Date7.Text = txtDate.AddDays(6).ToShortDateString();

Sucharitha Goud
Bank Of America..

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response