按月算

DateTime dt1= DateTime.Parse("2011-11-2");
   DateTime dt2
= DateTime.Parse("2011-10-1");
   
if(dt1.AddMonths(-1)>dt2)
     Console.WriteLine(
"more than one month");
   
else Console.WriteLine("less than one month");

string MonthStart = DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + "1" + " " + "00:00:00";

string MonthEnd = Convert.ToString(Convert.ToDateTime(MonthStart).AddMonths(1).AddSeconds(-1));

你可能感兴趣的:(按月算)