Alex Rivera | Logout

Nearest completed quarter

Asked 2009-12-22T15:44:43.417
13

Is there a C# function which will give me the last day of the most recently finished Quarter given a date?

For example,

var lastDayOfLastQuarter = SomeFunction(jan 3, 2010);

would set lastDayOfLastQuarter = Dec 31, 2009

Edit
Report

1 Answer

3

A simple function can calculate the last days of the most recently completed month:

public static DateTime LastQuarter(DateTime date)
{
    return new DateTime(date.Year, date.Month - ((date.Month - 1) % 3), 1).AddDays(-1);
}
answered 2009-12-22T16:03:33.630

Your Answer