日期:2014-05-17  浏览次数:20427 次

求两个时间点的时间季度差
两个时间,比如一个:2010-03-01 一个:2012-05-01 怎样算出这两个时间相差几个季度。不用sql 处理。

------解决方案--------------------
如果你的需求是 2011-03-16 为第一季度,2012-05-26 为第二季度,则相差5个季度,这种逻辑的话: 
DateTime dtStart = dateTimePicker1.Value;
DateTime dtEnd = dateTimePicker2.Value;
DateTime temp = new DateTime();
if (dtStart > dtEnd)
{
temp = dtStart;
dtEnd = dtStart;
dtStart = temp;
}
int diffyear = (dtEnd.Year - dtStart.Year) * 4;
int diffmonth = ((dtEnd.Month - 1) / 3) - ((dtStart.Month - 1) / 3);
int diff = diffyear + diffmonth;