Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Get Quarter Starting and Ending Dates for a given Date

, 19 Mar 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
To calculate the quarter, you can use the Time Period Library for .NET:// ----------------------------------------------------------------------public static void ShowQuarterInfo( YearMonth yearBaseMonth = YearMonth.January ){ ShowQuarterInfo( DateTime.Now, yearBaseMonth );} //...
To calculate the quarter, you can use the Time Period Library for .NET:
// ----------------------------------------------------------------------
public static void ShowQuarterInfo( YearMonth yearBaseMonth = YearMonth.January )
{
  ShowQuarterInfo( DateTime.Now, yearBaseMonth );
} // ShowQuarterInfo

// ----------------------------------------------------------------------
public static void ShowQuarterInfo( DateTime moment, YearMonth yearBaseMonth = YearMonth.January )
{
  // set start month to year
  TimeCalendar calendar = new TimeCalendar(
    new TimeCalendarConfig { YearBaseMonth = yearBaseMonth } );
 
  // working quarter
  Quarter quarter = new Quarter( moment );
  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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jani Giannoudis
Software Developer (Senior)
Switzerland Switzerland
Jani is Co-founder of Meerazo.com, a free service which allows to share resources like locations, things, persons and their services in a cooperating group of people.

Comments and Discussions

 
GeneralThank you. Very useful library. Infact, I am unaware of thi... PinmemberRavi LVS18-Mar-11 17:29 
GeneralReason for my vote of 5 Good PinmemberRavi LVS18-Mar-11 17:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 19 Mar 2011
Article Copyright 2011 by Jani Giannoudis
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid