Simple Year Pivoting Function
Submitted by brian on Tue, 10/06/2009 - 2:54am.
Year after year you know you have a product that will be updated at a[round] a certain month. It happens a lot with my business domain. Rather than changing lots of text, this should work nicely for my needs. (I didn't use any timezone or culture considerations)
the pivot month is the int that decides when we flip to next year.
/// <summary> /// Figures out if should use this year ///or next based on a defined pivot month. /// </summary> /// <returns>4 digit year</returns> public int YearPivot(DateTime dt, int pivotMonth) { return (dt.Month <= pivotMonth) ? dt.Year : dt.AddYears(1).Year; }
couple tests showing it in action...
DateTime dt = new DateTime(2009, 10, 1); //returns 2009 Assert.AreEqual(2009, m.YearPivot(dt, 10)); //returns 2010 Assert.AreEqual(2010, m.YearPivot(dt, 5));
Tags:

















no problem!
- reply
Submitted by brian on Thu, 10/29/2009 - 4:02am.great job bos,thank a lot.best wish for you.
- reply
Submitted by naniek (not verified) on Wed, 10/28/2009 - 1:43am.