Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nearest completed quarter

Tags:

date

c#

.net

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

like image 531
Ian Vink Avatar asked Dec 22 '09 15:12

Ian Vink


People also ask

What does it mean to round to the nearest quarter?

The calculation takes the integer (the number to the left of the decimal) and adds it to the deminal part of the number (the number to the right of the decimal) that has been divided by 25 to provide the correct quarter value. Answer Number: 000022991. Products.

How do you find the nearest quarter hour?

When reporting time not worked, employees should round to the nearest 1/4 hour. For example: 15 minutes = 0.25 hours, 30 minutes = 0.50 hours and 45 minutes = 0.75 hours.

How do you round 0.25 in Excel?

To round a number down to nearest 0.5, use the FLOOR function, for example =FLOOR(A2, 0.5) . To round a number up to nearest 0.5, use the CEILING function, for example =CEILING(A2, 0.5) . To round a number up or down to nearest 0.5, use the MROUND function, e.g. =MROUND(A2, 0.5) .

How do you round to the nearest quarter in Excel?

Enter this formula: =MROUND(A2,"0:15") or =MROUND(A2,"0:30") into a blank cell beside your data which need to round to nearest quarter or half hour, and then drag the fill handle down to the cells you want to apply this formula, and you will get a list of decimal numbers, see screenshot: 2.


1 Answers

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);
}
like image 102
Greg Avatar answered Oct 14 '22 21:10

Greg