Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi.
how can i get the previous three dates from the current date. for example the current date is 16/07/2011. so can i get the previous dates(15/07/2011,14/07/2011,13/07/2011).note that month can also be changed. like if date is 01/07/2011 and i want to get the previous three dates so in this case not only day but also month will be changed. so please tell me how to do this using asp.net with c#
Posted

1 solution

Try below code.

C#
DateTime currentDate = System.DateTime.Now;
StringBuilder previousThreeDates = new StringBuilder();
DateTime previousDate;

for (int i = 1; i < 4; i++)
{
 previousDate = currentDate.AddDays(-i);
 previousThreeDates.Append(previousDate.ToString("dd/MM/yyyy"));
 if (i < 3)
  previousThreeDates.Append(",");
}

Response.Write(previousThreeDates.ToString());
 
Share this answer
 
v2

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