In C#, is there any more elegant way to take a DateTime and calculate how many months until the "next" Quarter? [closed]

This should do it:

int untilNextQuarter = 4 - (currentMonth % 3);

Or a slightly clearer but slightly less efficient approach:

int[] remainingMonths = new[] { 3, 2, 4 };
int untilNextQuarter = remainingMonths[(currentMonth - 1) % 3];

Browse More Popular Posts

Leave a Comment