Friday, March 13, 2020

How to generate List of previous 12 months with year from DateTime.Now

var lastSixMonths = Enumerable.Range(0, 12)
                                   .Select(i => DateTime.Now.AddMonths(i -12))
                                    .Select(date => date.ToString("MMM"));


Output :
  "Mar"
"Apr"
"May"
"Jun"
"Jul"
"Aug"
"Sep"
"Oct"
"Nov"
"Dec"
"Jan"
"Feb"


var lastSixMonths = Enumerable.Range(0, 12) .Select(i => DateTime.Now.AddMonths(i -12)) .Select(date => date.ToString("MM/yyyy"));

Output :
  "03/2019"
"04/2019"
"05/2019"
"06/2019"
"07/2019"
"08/2019"
"09/2019"
"10/2019"
"11/2019"
"12/2019"
"01/2020"

"02/2020"

No comments:

Post a Comment

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...