Skip to content

Instantly share code, notes, and snippets.

@SamWM
Created March 16, 2012 11:17
Show Gist options
  • Save SamWM/2049643 to your computer and use it in GitHub Desktop.
Save SamWM/2049643 to your computer and use it in GitHub Desktop.
Show dates a year before and after current date
DateTime currentDate = DateTime.Now;
DateTime loopDate;
for (loopDate = currentDate.AddMonths(-11); (loopDate - currentDate).Days < 365; loopDate = loopDate.AddMonths(1))
{
if(loopDate == currentDate)
{
Console.Write("<<");
}
Console.Write(loopDate.ToString("MMMM yyyy"));
if(loopDate == currentDate)
{
Console.Write(">>");
}
Console.Write(Environment.NewLine);
}
Console.ReadLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment