15,610,088 members
See more:
how to calculate the quarter of the year from the starting date to Next Date like first Quarter is Start from April to June so the first date of quarter and the Last Date of Quarter

Posted
Updated 22-Oct-10 18:46pm
v2
shakil0304003 23-Oct-10 2:55am
Your requirement is little bit confusing. Clear it what you want?

Solution 1

Hi

i didnt check this code, pls check this code..

```int GetQuarterName(DateTime myDate)
{
return Math.Ceiling(myDate.Month / 3);
}
DateTime GetQuarterStartingDate(DateTime myDate)
{
return new DateTime(myDate.Year,(3*GetQuarterName(myDate))-2,1);
}```

v2
Hiren solanki 23-Oct-10 2:20am
added 'pre' tags for code visibility.

Solution 3

To calculate the quarter based on the month April, you can use the Time Period Library for .NET:
C#
```// ----------------------------------------------------------------------
public static void ShowQuarterInfo()
{
ShowQuarterInfo( DateTime.Now );
} // ShowQuarterInfo

// ----------------------------------------------------------------------
public static void ShowQuarterInfo( DateTime moment )
{
// set start month to April
TimeCalendar calendar = new TimeCalendar(
new TimeCalendarConfig { YearBaseMonth = YearMonth.April } );

// working quarter
Quarter quarter = new Quarter( moment, calendar );
Console.WriteLine( "Quarter start: " + quarter.FirstDayStart );
Console.WriteLine( "Quarter end: " + quarter.LastDayStart );

// previous quarter
Quarter previousQuarter = quarter.GetPreviousQuarter();
Console.WriteLine( "Previous Quarter start: " + previousQuarter.FirstDayStart );
Console.WriteLine( "Previous Quarter end: " + previousQuarter.LastDayStart );

// next quarter
Quarter nextQuarter = quarter.GetNextQuarter();
Console.WriteLine( "Next Quarter start: " + nextQuarter.FirstDayStart );
Console.WriteLine( "Next Quarter end: " + nextQuarter.LastDayStart );
} // ShowQuarterInfo```

You will find more samples in the article Time Period Library for .NET[^].

Cheers, Jani.

Solution 2

Example:
```private void make(int year, int quarter)
{
DateTime starting, ending;
int month = (4 + 3 * (quarter - 1)) % 12;

starting = new DateTime(year, month, 1);
MessageBox.Show(starting.ToString() + "," + ending.ToString());
}

make(2010, 1);
make(2010, 2);
make(2010, 3);
make(2010, 4);```