Geeks With Blogs
Rohit Gupta Engaging talk on Microsoft Technologies ....My Resume

Companies usually have differing Fiscal Year End dates some have it as 3/31/2009 some have have it as 6/30/2009 and some 12/31/2009

Thus if you need to get the Quarter end date based on differing Fiscal Year end dates… you can use this function I created to get Quarter end dates:

   1: public static class ExtensionMethods
   2: {
   3:     public static DateTime MonthEnd(this DateTime date)
   4:     {
   5:         return new DateTime(date.Year, date.Month, 1).AddMonths(1).AddDays(-1);
   6:     }
   7: }
   8:  
   9: public class CalcUtils
  10: {
  11:     public static DateTime GetLastDayOfQuarter(string selectedQuarter, DateTime fyeDate, int selectedYear)
  12:     {
  13:         DateTime date = DateTime.MinValue;
  14:         DateTime adjustedDate = new DateTime(selectedYear - 1, fyeDate.Month, 1);
  15:         adjustedDate = new DateTime(adjustedDate.Year, adjustedDate.Month, adjustedDate.MonthEnd().Day);
  16:  
  17:  
  18:         int quarter = Convert.ToInt32(selectedQuarter[selectedQuarter.Length - 1].ToString());
  19:  
  20:         switch (quarter)
  21:         {
  22:             case 1:
  23:                 date = adjustedDate.AddMonths(3);
  24:                 break;
  25:  
  26:             case 2:
  27:                 date = adjustedDate.AddMonths(6); 
  28:                 break;
  29:  
  30:             case 3:
  31:                 date = adjustedDate.AddMonths(9); 
  32:                 break;
  33:  
  34:             case 4:
  35:                 date = adjustedDate.AddMonths(12); 
  36:                 break;
  37:         }
  38:  
  39:         return date;
  40:     }
  41: }
  42:  
  43: To call this method use : 
  44: DateTime x2 = CalcUtils.GetLastDayOfQuarter("Qtr1", new DateTime(2009,12,31), 2010);

Hope this helps

Posted on Tuesday, February 9, 2010 1:15 PM | Back to top


Comments on this post: Get Quarter End Date depending on the Fiscal Year end date

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Rohit Gupta | Powered by: GeeksWithBlogs.net