Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
How to enter the date and the date 7 days after we get ?(in C#)
insert date : 2011/11/08
get date 1 : 2011/11/09
get date 2 : 2011/11/10
get date 3 : 2011/11/11
.
.
.
get date 7 : 2011/11/15
Thanks.
Posted
Updated 18-Dec-11 21:57pm
v2

try this..

C#
DateTime dt = Convert.ToDateTime(Console.ReadLine());
for (int i = 1; i < 7; i++)
{
    Console.WriteLine(dt.AddDays(i).ToShortDateString());
}


hope it helps..
 
Share this answer
 
C#
DateTime date = Convert.ToDateTime(Console.ReadLine());
 for (int i = 0; i < 7; i++)
 {
     Console.WriteLine(date.AddDays(i).ToShortDateString());
 }
 
Share this answer
 
v3
Comments
Karthik Harve 19-Dec-11 4:13am    
Edit: Pre tags added.
do you want to add days to entered date ?

C#
System.DateTime today = System.DateTime.Now;
System.DateTime answer = today.AddDays(7);
MessageBox.Show(answer.Tostring("MM/dd/yyyy"));


in above we have added 7 days in current date.
 
Share this answer
 
Here it is :

C#
DateTime startdate = new DateTime(2011, 12, 28);
for (int i = 1; i <= 7; i++)
{
    Console.WriteLine(startdate.ToString());
    startdate = startdate.AddDays(i);
}
Console.WriteLine(startdate.ToString());



Hope it helps.
 
Share this answer
 
I wrote this:
(But with your help)

C#
DateTime dateConvert = Convert.ToDateTime(dateGet);
dateShow1.Text = dateConvert.AddDays(1).ToString();
dateShow2.Text = dateConvert.AddDays(2).ToString();
...
 
Share this answer
 
v2
Comments
Wendelius 19-Dec-11 12:45pm    
Pre tags added to enhance code readability
Prashant Srivastava LKO 22-Jan-12 12:46pm    
Sir how u add these tags When I use The color not changes
Hi fiend,

Suppose your textbox id is

ASP.NET
<asp:TextBox ID="txtDates" runat="server"></asp:TextBox>

call the below code in Page Load will get what u want

C#
txtDates.Text = System.DateTime.Now.ToString("dd/MM/yyyy");   


The Format you can change according to your need I am using dd/MM/yyyy
 
Share this answer
 
v2
Comments
Karthik Harve 19-Dec-11 4:16am    
Edit: pre tags added.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900