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 = So
Assuming quarters always end at 3 month intervals you could do:
Maybe not the best solution, but very easy to read and modify compared to other solutions offered.
public DateTime LastDayOfLastQuarter(DateTime date)
{
int result = (int)(date.Month/3)
switch (result)
{
// January - March
case 0:
return new DateTime(date.Year - 1, 12, 31);
// April - June
case 1:
return new DateTime(date.Year, 3, 31);
// July - September
case 2:
return new DateTime(date.Year, 6, 30);
// October - December
case 3:
return new DateTime(date.Year, 9, 30);
}
}