DateTime dateNow = DateTime.Now;
string excelMonth = "July";
int lessNumberOfMonth = dateNow.ToString("MMMM").ToLower().Equals(excelMonth.ToLower()) ? 0 : 1;
Console.WriteLine(lessNumberOfMonth);
string dateString = string.Format("{0} 1, {1}", "june", dateNow.AddMonths(-lessNumberOfMonth).Year);
DateTime dt = DateTime.ParseExact(dateString, "MMMM d, yyyy", new CultureInfo("en-US"));
Console.WriteLine(dt);
Comments
Post a Comment