当前位置: 代码迷 >> ASP.NET >> 求两个时间点的时间季度差解决方案
  详细解决方案

求两个时间点的时间季度差解决方案

热度:5326   发布时间:2013-02-25 00:00:00.0
求两个时间点的时间季度差
两个时间,比如一个: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;
  相关解决方案